0 Replies Latest reply on Nov 15, 2009 9:11 PM by Adobe-InDesign CS4

    [JS-CS4] - How to read the XML Element and its Attributes

    Adobe-InDesign CS4 Level 1

      Dear All,

       

        I have the doubt regarding: reading the xmlElement and its attributes.

       

      Here I droping the xml script

       

      //============= Start ======================//

       


      var myDoc = app.activeDocument;

      var Fpath = File("../Projects/Entity_map.xml");
        if (Fpath.exists)
        {
         Fpath.open("r");
         var Cont= Fpath.read();

        var roots = new XML(Cont);
        var myEveryName = new Array();
        var myEveryContent = new Array();
        var myEveryAttributes = new Array();
        traverse(roots);
      }

      //$.writeln(myEveryName);
      //$.writeln(myEveryContent);
      $.writeln(myEveryAttributes.length);

      for(var i=0; i<myEveryAttributes.length; i++)
      {
        $.writeln(myEveryAttributes[i]);
        }

      function traverse(tree) {
          myEveryName.push(tree.name());
      myEveryContent.push(tree.text());
        

        myEveryAttributes.push(tree.getAttribute);


      // you get the contents by using .text() insted of .name()
          if(tree.elements().length() > 0) {
              for(var i=0; i<tree.elements().length(); i++) {
                  traverse(tree.elements()[i]);
              }
          }
      }

       

      //============== End =====================//

       

       

      and the XML Structure is

       

      //===============XML =====================//

       

      <?xml version="1.0" encoding="UTF-8"?>

      <

       

      Entity_Convertion>

      <

       

      Entitys char="Ç" GID="173"/>

      </

       

      Entity_Convertion>

       

      //===============End ====================//

       

       

       

      Here I'm getting the XML Elements and its contents, but not xmlAttributes.

       

      Please any one can help me, then I will appreciate...

       

       

      Thanks & Regards

      T.R.Harihara SudhaN