3

Possible Duplicate:
InDesign CS5 Script: How can I ignore the DTD when importing XML?


Here is a basic XML file with a DTD file declaration:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article SYSTEM "blahblah.dtd">
<root-node></root-node>


I found this XSL solution at http://www.stylusstudio.com/xsllist/200104/post90620.html, which is not working:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

( ...tested at http://www.w3schools.com/XSL/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_ex2 )



So, is there any other way to ignore the !DOCTYPE declaration, or otherwise ignore the DTD file?
Community
  • 1
  • 1
Ian Campbell
  • 2,678
  • 10
  • 56
  • 104
  • 1
    This isn't XSLT problem but XML problem. XSLT operates on the XML document that is already parsed by an XML parser -- it is too late for the XSLT processor to perform any XML lexical changes. It is probable that there exist XML parsers that have a commndline switch to ignore a DOCTYPE. However, in general ignoring a DTD may result in a non-wellformed XML document -- so this operation generally is unsafe. – Dimitre Novatchev Aug 01 '12 at 01:53
  • Your XSL probably is working and just appears to not be working using the w3schools online tool. Please see my comment to you in my answer to the first question you asked (this is a duplicate). – Daniel Haley Aug 01 '12 at 03:08
  • Haha, ok fine, I just flagged this question as well. Anyway, it *does* appear to work in other online utilities as opposed to the w3schools one as you suggest @DevNull, but is *not* working in Adobe InDesign (as my first question is directed towards). – Ian Campbell Aug 01 '12 at 03:36
  • Thanks @Dimitre for the explanation, it's making a little more sense now.. So, ignoring a DTD can result in a non-wellformed XML document, but what if the DTD is externally linked and not directly accessible? – Ian Campbell Aug 01 '12 at 04:15
  • @IanCampbell: Why do you thin this case is different? Exactly the same considerations apply in both cases. – Dimitre Novatchev Aug 01 '12 at 04:19
  • 1
    The problem is, is that the program I am using cannot access the DTD (nor can I), and so is causing a namespace error. The DTD is generated by a web-service of sorts for the program that exports the XML. – Ian Campbell Aug 01 '12 at 04:42
  • 1
    I'm surprised this question was closed as an "exact duplicate." The supposed duplicate question covers InDesign/CS, and its solutions are in ExtendScript, which is no help at all for an XSLT case. Yes the author is the same, but a goal of SO is that others looking for answers to this question (how to bypass a DOCTYPE reference from XSL) will be able to benefit from the answer. – LarsH Dec 18 '12 at 11:50

1 Answers1

0

I would use a regex to parse the xml and remove the Doctype declaration.

zanegray
  • 768
  • 7
  • 13
  • Yep, a quick bit of pre-processing seems to be simplest solution here. – Spudley Jul 31 '12 at 21:53
  • 2
    Yes, but is this possible with XSL? – Ian Campbell Jul 31 '12 at 23:08
  • No, it's not possible with XSLT. An XSLT processor simply asks the XML parser to process the input and provide the result in the form of a tree. – Michael Kay Aug 01 '12 at 08:53
  • 2
    @MichaelKay: But as you are of course aware, very often the XSLT processor can pass parameters to the parser to influence its behavior. For example, Saxon 9 has the -dtd:off and -expand:off command-line options. Granted these options have consequences that the OP may not want, but nevertheless don't you think they deserve mention, as they could help the OP in the case where the referenced DTD is inaccessible? – LarsH Dec 18 '12 at 11:45
  • 1
    @LarsH I would have mentioned these options if they helped with the problem, but they don't. If the DTD is inaccessible, you will get a failure whatever these option settings. – Michael Kay Dec 18 '12 at 15:29
  • 1
    @MichaelKay: thanks, good to know. From the documentation online (http://www.saxonica.com/documentation/using-xsl/commandline.xml), it wasn't clear to me whether either of these, especially -expand:off, would help if the DTD were inaccessible. – LarsH Dec 19 '12 at 20:43