2 Replies Latest reply on Dec 3, 2015 2:43 AM by pav55

    populate selected tag from xml into dropdownlist SUI

    pav55 Level 1

      hi guys,

      I'm trying to display xml 1 tag type values only in dialogbox dropdownlist.

      I can read and display content but whatever I'm trying to do to get wanted result getting the same results - dropdown displays all content with tags from file as a line (equal dropdown item) multiple by amount of signs or every sign from file appear in dropdown as item.


      my xml stucture is:


        <colour default="true">

          <name>color name 1</name>

          <value>my cmyk value 1</value>


        <colour default="true">

          <name>color name 2</name>

          <value>my cmyk value 2</value>



      do you know maybe how I can display only <name> of every colour as an dropdownlist item?

      will appreciate any help...my idea to construct question to uncleG finished


      the part of code responsible for reading xml is:


      var colourNames = [];

      var file_to_read = File("/myFilePath/test.xml");

      var content;


      content = file_to_read.read();

           //var my_XML_object = null;

           //my_XML_object =  XMLList(content).toSource();


      for (x = 0; x < content.length; x++) { 

          var xmlitem = content[x]; 

         colourNames.push (xmlitem);   



      commented lines are something I've try as well, maybe will be useful.

      Thank you

        • 1. Re: populate selected tag from xml into dropdownlist SUI
          steverocket2 Level 1

          Hi pav,


          you need to read the contents of the file and then create a JavaScript XML Object from it.

          Then you have access to the elements of the xml:



          var curFileString = this.file.read();

          this.XML = new XML(curFileString);


          The JavaScript XML Element is not the XMLElement for the InDesign document.


          • 2. Re: populate selected tag from xml into dropdownlist SUI
            pav55 Level 1

            Hi Stefan,

            thank you for your answer and time.

            Have it already solved.


            You right it wasn't necessary to create array but just display data.


            maybe will be useful for somebody in the future (there are not so many complete samples around www. lots of info you have to guess) so solution looks like that:

            xml structure:

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


              <colour default="true">

                <itemName>my colour name will be display in dropdown list</itemName>






              <colour default="true">

                <itemName>my colour name2 will be display in dropdown list</itemName>










            //---read xml before dialog open---//

            var prefXMLFile = File("/myFilePath/test.xml");

            var myResult = prefXMLFile.open("r", undefined, undefined);

            if(myResult == true){

            var xmlstr = prefXMLFile.read();




            alert("Something wrong with xml file - call the police :)")



            var xmlobj = new XML (xmlstr);

            var myitems= xmlobj.colour.length(); //---getting colour item which will be populated in dropdown in dialogbox


            //-- and now what tried to do was display itemName in dropdown and keep another 4 values to work with later


            //-- adding dropdown to dialogbox selected group:


            var myDD = colour_group.add ("dropdownlist", undefined, undefined);

               for (i=0;i<myitems;i++)


                var curitem= xmlobj.colour[i].itemName.toString();




            //--after setup all parameters in dialogbox and close it in rest part of the script I'm getting rest of the values as numbers


            var c= parseInt(xmlobj.colour[myDD.selection.index].myC.toString());

            var m= parseInt(xmlobj.colour[myDD.selection.index].myM.toString());

            var y= parseInt(xmlobj.colour[myDD.selection.index].myY.toString());

            var k= parseInt(xmlobj.colour[myDD.selection.index].myK.toString());


            hope it will helps to somebody.

            (sorry for not using code frame but dont know how)


            thanks again Stefan