1 Reply Latest reply on May 16, 2014 6:24 AM by schiuma24

    How to check if an XML Element is on a page item (javascript)


      Hi people, i have this book template with script labels that matches my average XML document, but some times my content creation people get fancy and create elements that are not contemplated on my document, when I import these xml files, those contents obviously won't get on the document, so, i need to inspect my xml Tree, and find whichever node isn't on my layout and pour it on a new text frame on the pasteboard, the thing is that i don't know how to inspect an xmlElement that way with javascript.

      any help will be highly appreciated! this is an example of the xml file



      <learningXECContent outputclass="sidebar">bla bla bla bla</learningXECContent>

      <learningXECContent outputclass="footnote">bla bla bla bla</learningXECContent>

      <learningXECContent outputclass="body">bla bla bla bla</learningXECContent>



      i want to loop through this 3 elements and find the one that is not poured into the document.




        • 1. Re: How to check if an XML Element is on a page item (javascript)
          schiuma24 Level 1

          Ok, now im able to see the type of content the node has, but cant come up with an if statement that returns true for "Text"


          var myDoc = app.activeDocument;

          var xml = myDoc.xmlElements[0];



          //////*****MAKES XPATH HAPPY AND COOPERATIVE*****////////////////////////////////////

          if( !xml.xmlAttributes.itemByName("xmlns:xml").isValid )

          xml.xmlAttributes.add( "xmlns:xml", "http://www.w3.org/XML/1998/namespace" );

          if( !xml.xmlAttributes.itemByName("xmlns:aid").isValid )

          xml.xmlAttributes.add( "xmlns:aid", "http://ns.adobe.com/Adobe InDesign/4.0/" );

          if( !xml.xmlAttributes.itemByName("xmlns:aid5").isValid )

          xml.xmlAttributes.add( "xmlns:aid", "http://ns.adobe.com/Adobe InDesign/5.0/" );

          ////////////////////////////////////////////////////////////////////////////////////////// ///   



          var myNode= xml.evaluateXPathExpression("//learningBECContent");



          for (i = 0; i < myNode.length; i++){



          //if(myNode[i].xmlContent == ){


          //alert("bla bla")