1 Reply Latest reply on Aug 13, 2013 10:40 PM by Vamitul

    Getting element contents from any XML structure with Extendscript in InDesign

    timberjava

      I have the following simple structure that I want to get the contents out for each element:

      <Root>

        <Story>

          <ChapterTag>"Chapter 1"</ChapterTag>

          <SubChapterTag>"Sub Chapter 1"</SubChapterTag>

          <ChapterTag>"Chapter 2"</ChapterTag>

          <SubChapterTag>"Sub Chapter 2"</SubChapterTag>

          <SubChapterTag>"Sub Chapter 2 More"</SubChapterTag>

        </Story>

      </Root>

      (Yes, the ChapterTag and the SubChapterTag are on the same level)

       

      With the following lines of code, I can *successfully* get each of the tag names:

      var myDocument = app.documents.item(0);

      var arrayOfTagNames = myDocument.xmlTags.everyItem().name;

      >>> Array loop lists out:

      "Root

      Story

      ChapterTag

      SubChapterTag"

       

      However, I am stumped as to now getting the contents, or data for each of these tag elements!  I want to get all instances of contents, including the two instances of ChapterTag and SubChapterTag to  get a similar list like:

      "Chapter 1

      Sub Chapter 1

      Chapter 2

      Sub Chapter 2

      Sub Chapter 2 More"

       

      I thought that the following code would get me close:

      var arrayOfTagContents = mydocument.xmlElements.everyItem.getElements().

       

      But alas, I confess that somehow I am not operating on the correct object.  Does anyone have a solution for me (aside from XMLRules) to solve this dilemma of getting the contents out?  I am not resistant to XMLRules, but I want to know why I cannot seem to get contents for each tag element when I can get the name for the tags.

       

      My thanks in advance.