Skip navigation
racecar333
Currently Being Moderated

How can I remove or add namespaces to a document?

Aug 1, 2012 7:25 PM

Tags: #cs5 #indesign #xml #namespaces #extendscript #xslt #dtd

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.

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points