0 Replies Latest reply on Dec 16, 2009 10:25 PM by (MightyJack)

    Help listing and selecting xml object

    (MightyJack) Level 1

      Hi there

       

      I am having problems with "see the forrest" with this code. I am trying to sort a my xml elements by listing them , sorting them and moving them.

       

      My problem is :

      How do i make a list of all my elements in the "story" like a collection of indesign elements ?

      How do i select the element and move it after "myXMLOld" ?

       

      And if this is a "BAD" way to to this i will be interested to learn a better way ?

       

      Regards

      T'

       

       

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

          var myXML = myDocument.xmlElements.itemByName("Root").xmlElements.itemByName("Story")

            var myXmlList = new Array;

          var bb = myXML.xmlElements.length;

      for(var myCounter = 0; myCounter < bb; myCounter++){

           var  myXmlElement= myXML.xmlElements.item(myCounter)

           var myXM_id = myXML.xmlElements.item(myCounter).id;

           var myXML_con = myXML.xmlElements.item(myCounter).contents;

           myXmlList[myCounter] = [[myXML_con , myXM_id]];

           }

      var ok = myXmlList;

      myXmlList.sort ()

      var myXMLOld=myXmlList[0][0][1];

        var myXMLElementA = myXML.xmlElements.itemByID(myXmlList[0][0][1]);

      myXMLElementA.move(LocationOptions.atBeginning);

      for(var myCounter = 1; myCounter < bb; myCounter++){

      var test = myXmlList[myCounter][0][1];

      var myXMLElementA = myXML.xmlElements.itemByID(test);

           myXMLElementA.move(LocationOptions.after, myXML.xmlElements.xmlElements.itemByID(myXMLOld));

            var myXMLOld=myXmlList[myCounter][0][1];

           }

       

      XML file:

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

      <Root>

      <Story>

      <Vidlex>Alger: En stor gruppe </Vidlex>

      <Vidlex>Basalt: Sort finkornet /Vidlex>

      <Vidlex>Cyanobakterier: Bakterier, </Vidlex>

      <Vidlex>Dna: (Deoxyribonukleinsyre). Organisk molekyle, </Vidlex>

      <Vidlex>Etolog: Person, der </Vidlex>

      </Story>

      </Root>