1 Reply Latest reply on Aug 18, 2015 2:37 AM by Ronald63

    read an array of xmltags in reverse order

    aviR Level 1

      Hello all

      Can anyone please tell me how can I read an arraylist of xml tags in reverse order?

      arraylist.reverse() method doesnt work with indesign. Please tell me what should i do?

      Please help.

      Thanks

        • 1. Re: read an array of xmltags in reverse order
          Ronald63 Level 4

          Hello,

           

          Hope this snippet help you ...

          var myArray = []
          //define XML
          xmlStr = "<root>";
          xmlStr += "<datas>";
          xmlStr += "<data>foo1</data>"; 
          xmlStr += "<data>foo2</data>";
          xmlStr += "<data>foo3</data>";
          xmlStr += "<data>foo4</data>";
          xmlStr += "<data>foo5</data>";
          xmlStr += "</datas>";
          xmlStr += "</root>";
          //create XML objecr
          var mXML = new XML (xmlStr);
          //count <data> element
          var countElements = mXML.datas.elements().length();
          // loop 
          for  (var i = 0; i < countElements; i++){
              myArray.push(mXML.datas.child(i))
          }
          //reverse array
          myArray.reverse();
          alert(myArray)
          
          // ANOTHER WAY
          
          var myArray1 = []
          //reverse loop
          for(i=countElements-1;i>=0;i--){
              myArray1.push(mXML.datas.child(i))
          }
          alert(myArray1)