3 Replies Latest reply on Sep 21, 2009 7:30 AM by Novistorm

    Javascript element content without child elements CS3

    Novistorm

      Hi,

       

      i have the following problem which i hope you guys can help me with.

      i have create the following xml structure in idesign

       

      <root>

      <story>

           <element1>

                <subelement>this is some content in subelement</subelement>

                this is some content in element1

           </element1>

      </story>

      </root>

       

      now i want to get with javascript the content of element1.

      but then i use the following code

       

      var xmlelement = some code to get element1

      xmlelement.contents or xmlelement.xmlContent.contents

       

      i get this text returned

      this is some content in subelement

      this is some content in element1

       

      and not only this text

      this is some content in element1

       

      i want only the content from element1 and not element1 and all his sub elements

        • 1. Re: Javascript element content without child elements CS3
          AdobeScripts Level 3

          Novistorm wrote:

           

          i want only the content from element1 and not element1 and all his sub elements

           

          but contents of element1 contains all sub-elements

           

          you need to get contents of element1 to variable and then get positions and length of all sub-elements and delete it from this variable ...

           

          ... or you can copy whole element1 to new TextFrame and then delete all sub-elements and then you will have only element1.contents

           

          robin

           

          www.adobescripts.co.uk

          1 person found this helpful
          • 2. Re: Javascript element content without child elements CS3
            Novistorm Level 1

            ok ty, i'll search for the method to get the positions since i need the text of the other elements aswell (not at the same time though) so retrieval must be in the same order as in the xml

            • 3. Re: Javascript element content without child elements CS3
              Novistorm Level 1

              Hmm dont get it working yet

               

              i want to get the data but it must be in order from the elements

              if i use this example again with a little addition

              <root>

              <story>

                   <element1>

                        <subelement>this is some content in subelement</subelement>

                        this is some content in element1

                         <subelement2>this is some content in subelement2</subelement2>

                   </element1>

              </story>

              </root>

               

              i want to loop through the element1 so i can make a array like this

               

              array['subelement'] = 'this is some content in subelement'

              array['element1'] = ' this is some content in element1';

              array['subelement2'] = 'this is some content in subelement2';

               

               

              the element ordering is most of the time different the same it could also been this for example

               

              <root>

              <story>

                   <element1>

                        <subelement>this is some content in subelement</subelement>

                        <subelement2>this is some content in subelement2</subelement2>

                        this is some content in element1

                         <subelement>this is some content in subelement</subelement>

                        this is some content in element1

                   </element1>

              </story>

              </root>