2 Replies Latest reply on Jul 23, 2010 4:13 PM by Loic.Aigon

    [JS] Problem defining an object while grabbing info from xmlElements

    Loic.Aigon Adobe Community Professional



      Here is some piece of code I wrote in order to create an object. This object is expected to contain a property whise name is based on the value of

      the "airport_title" tag. I set the value to the page the xmlElement is on.

      The XML STructure in Indesign is like this :

      Image 3.png


      Image 1.png


      When I run this code, I can see that the properties have been defined. However, if I try to access them, it returns undefined.


      More confusing is that I place a dummy "toto" property which is available.

      obj["toto"] //28500 as expected.


      I am out of ideas here. Any hint ?


      TIA Loic


      PS: I checked the my variable airport_title variableconbstructor and that's a string.

      Image 2.png


      Here is the code

      function makePageIndexFromAirportTemplate(aTemplate){
        //var tempDoc=app.open(aTemplate);  
        var tempDoc=app.activeDocument;
        var airportPages = {};
            var airports_catalogue = tempDoc.xmlElements[0];      
            var airport=airports_catalogue.xmlElements;
            var airportLength = airport.length;
          for(var i=0; i<airportLength; i++){
               var theAirport = airport[i];
               var bloc_airport = theAirport.xmlElements[0];
               var airportTitle = bloc_airport.contents;
               airportTitle = airportTitle.replace(/[ \-,;()]/g,"");
              // alert(bloc_airport.storyOffset.parentTextFrames[0].parentPage.name);
               var pg = bloc_airport.storyOffset.parentTextFrames[0].parentPage.name;
               //var airportTitle = "\""+airportTitle+"\"";
              return airportPages;
          return false; 
      var obj = makePageIndexFromAirportTemplate();
        • 1. Re: [JS] Problem defining an object while grabbing info from xmlElements
          [Jongware] Most Valuable Participant

          Perhaps there is a limit on how much "properties" an object can use, or the length of the name of the objects. Any practical reason you are using associative arrays? Perhaps you can change it to a simple array:


          var airportPages = [];
          airportPages.push ([airportTitle, [pg]);
          for (a=0; a<airportPages.length; a++)
            $.writeln (airportPages[a][0]+" "+airportPages[a][1]);


          (This also adds the advantage that you can sort on page numbers!)

          • 2. Re: [JS] Problem defining an object while grabbing info from xmlElements
            Loic.Aigon Adobe Community Professional

            Hi Theunis,


            In fact I realized later why it wasn't working. This is the same root matter than my post on xmlElement contents.


            I think that the properties were correctly defined in some way but the strings must have contained the markers.

            i.e. the property looked to be "toto" but i was in fact <xmlMarker>toto</xmlMarker>


            I didn't check that from then as I made things differently but I think this is the source for all my troubles.


            As you presumed, I changed to an array approach that did the trick once I understood the markers trick.


            Why object in the first place ? I like the fact to call a value associationg the object and the property. With an array you have to loop for every element to check if the data is the one you want. I find object more straight. But maybe I am wrong ?

            Anyway, that was my vision.


            Thx for your interest. And plus, you gave me one key feature for using arrays better than objects : sorting !