I have an XML file, with these DTD and namespace declarations:
<!DOCTYPE article SYSTEM "blahblah.dtd">
<article article-type="review-article" dtd-version="2.3" xml:lang="EN" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
I am working on a lengthy script that is importing XML into an InDesign document, and transforming the XML tags with XSLT into new tags that match pre-existing style-names in the document. This script crashes however, and displays this error message in the ESTK:
DOM transformation error: Invalid namespace.
I have imported the DTD successfully, but this doesn't stop this error. Do I have to add the namespaces in the code itself? I have tried this, but it is not working ("obj" is a global variable):
| with(obj.xmlTree) |
| { |
| addNamespace("http://www.w3.org/1999/xlink"); |
| addNamespace("http://www.w3.org/1998/Math/MathML"); |
| } |
Or does the "transformation error" indicate that it has something to do with the XSL? Here is the relevant code, which is all working except for the namespace error:
| function importXML(xslt) |
| { |
| // importing the eXtyles DTD here |
| obj.doc.importDtd(File("C:/Blah Blah/"blahblah.dtd") ); |
| with(obj.xmlTree) |
| { |
| addNamespace("http://www.w3.org/1999/xlink"); |
| addNamespace("http://www.w3.org/1998/Math/MathML"); |
| } |
| with(obj.doc.xmlImportPreferences) |
| { |
| // defining the XSL transformation settings here |
| allowTransform = true; // allows XSL transformation |
| transformFilename = File(xslt); // applying the XSL here |
| importStyle = XMLImportStyles.MERGE_IMPORT; // merges XML elements into the InDesign document, merging with whatever matching content |
| createLinkToXML = true; // link elements to the XML source, instead of embedding the XML |
| repeatTextElements = true; // repeating text elements inherit the formatting applied to placeholder text, **only when import style is merge! |
| ignoreWhitespace = true; // gets rid of whitespace-only text-nodes, and NOT whitespace in Strings |
| ignoreComments = true; |
| ignoreUnmatchedIncoming = true; // ignores elements that do not match the existing structure, **only when import style is merge! |
| importCALSTables = true; // imports CALS tables as InDesign tables |
| importTextIntoTables = true; // imports text into tables if tags match placeholder tables and their cells, **only when import style is merge! |
| importToSelected = false; // import the XML at the root element |
| removeUnmatchedExisting = false; |
| } |
| with(obj.doc) |
| { |
| mapXMLTagsToStyles(); // automatically match all tags to styles by name (after XSL transformation) |
| importXML(File(obj.xmlDoc) ); |
| } |
| alert("The XML file " + obj.xmlDoc.name + " has been successfully imported!"); |
| } // end of function importXML |
So, I would like to be able to add the namespaces to solve this problem, but it is not necessary as I only need the raw text of the XML itself. If it is easier, I would like to ignore the namespaces entirely, if this is possible.
Nevermind, I have found an awesome solution here: http://blog.fpmurphy.com/2008/02/remove-namespaces-from-xml-documents. html.
I tested this at http://xslt.online-toolz.com/tools/xslt-transformation.php, and it works! This XSL not only gets rid of all pesky namespaces, but also the !DOCTYPE apparently.
In my case, I have no need for the namespaces as I only need the raw XML text data itself. InDesign will have no use of the xlink namespace anyway.
p.s. -- my code looks crappy in those weird tables, ha.
North America
Europe, Middle East and Africa
Asia Pacific