2 Replies Latest reply on Feb 22, 2008 7:25 AM by srakete

    Adding Root Element

    Level 1
      Hi

      I have an existing structure in XML

      <article>
      <text>
      </text>
      </article>

      Here the element article is holding the content and is associated with the text frame.
      I would like to modify the structure to

      <Root>
      <article>
      <text>
      </text>
      </article>
      </Root>

      But still the article element should only be holding the content and shud be associated with text frame is it possible to do that either manually or through scripting in ID CS3

      Thanks
        • 1. Re: Adding Root Element
          Level 1
          Hi

          Any help on this.

          Thanks
          • 2. Re: Adding Root Element
            srakete Level 1
            Hi Priya,
            assume you have an Xml File imported
            <?xml version="1.0" encoding="UTF-8"?>
            <article>
            <text>myText</text>
            </article>

            and you have dragged <article> from the InDesign xml structure onto a textframe on the layout.
            Now, run this script to apply the Root-Tag to your article.

            myDoc = app.activeDocument;
            myArticleXmlElement = myDoc.xmlElements.item(0);
            myArticleXmlTag = myDoc.xmlTags.item("article");
            myTextXmlElement = myArticleXmlElement.xmlElements.item("text");
            try{
            myRootXmlTag = myDoc.xmlTags.add("Root");
            }
            catch(e){
            myRootXmlTag = myDoc.xmlTags.item("Root");
            }
            myArticleXmlElement.markupTag = myRootXmlTag;
            myNewArticleXmlElement = myDoc.xmlElements.item(0).xmlElements.add(myArticleXmlTag);
            myTextXmlElement.move(LocationOptions.AT_BEGINNING, myNewArticleXmlElement);

            Hope this is what you were looking for. You can do all of this manuallly as well. In fact this is how I began before writing the script.
            Just for curiosity, what is that for ? And can you not just import an Xml that already contains the root element ?

            Stefan