5 Replies Latest reply on Dec 16, 2009 2:01 PM by jpedroza2kLDS

    What is the purpose of...

    jpedroza2kLDS

      I am trying to use xmlElements.itemByName() but am getting unexpected results. Can someone please tell me how this functions. One would think that this would return an array of all the objects that match the string passed as a parameter. When I pass a string like "TOPIC-1". and then try and access any of the expected parameters, like length, id, index, etc, I get an error that the object is invalid. Sorry to post this, but the documentation on these is horrible.

       

      On that same vein, is there somewhere where the DOM is spelled out better than the InDesign CS3 Object Model under help in ExtendScript toolkit? I would even be quite happy to pick up a book from Amazon if it will give me a decent reference to the DOM and object model.

       

      Jared

        • 1. Re: What is the purpose of...
          Larry G. Schneider Adobe Community Professional & MVP

          You might check here

           

          http://www.jongware.com/idjshelp.html

           

          It's an .html version that is cross-referenced and much easier to use.

          1 person found this helpful
          • 2. Re: What is the purpose of...
            jpedroza2kLDS Level 1

            It is looking more and more that there is no easy way to search through the entire XML document tree and return an array of elements that match a specific name. Like: "Find all the elements whose name is TOPIC and put them into an array." I am thinking that I will need to write something that goes through the tree element by element and returns a reference to only those that match my query.

             

            Jared

            • 3. Re: What is the purpose of...
              [Jongware] Most Valuable Participant

              If it isn't in my help files, it doesn't exist ... probably

               

              Try adjusting this to your needs:

               

              var list = new Array;
              var tagname = "em"; // What tag you're looking for?
              
              findTags(app.activeDocument.xmlElements[0], list);
              
              alert ("List is "+list.length+" long");
              
              function findTags (root, addTo)
              {
                   var a;     // LOCAL; IMPORTANT!!
                   //     alert (root.markupTag.name);
                   if (root.markupTag.name == tagname)
                        addTo.push(root);
                   for (a=0; a<root.xmlElements.length; a++)
                        findTags(root.xmlElements[a], addTo);
              }
               
              

              • 4. Re: What is the purpose of...
                Kasyan Servetsky Level 5

                Here is my approach — use XML-rules:

                 

                #target indesign
                #include "/Applications/Adobe InDesign CS3/Scripts/Xml Rules/glue code.jsx"

                 

                var myDocument = app.activeDocument;
                var myName = "TOPIC-1";
                var myFoundElements = [];

                 

                var myRuleSet = new Array (new ProcessElements);

                 

                with(myDocument){
                    var elements = xmlElements;
                    __processRuleSet(elements.item(0), myRuleSet);
                }

                 

                alert("Found " + myFoundElements.length + " " +  myName + " elements");

                 

                function ProcessElements(){
                    this.name = "ProcessElements";
                    this.xpath = "//" + myName;  
                    this.apply = function(myElement, myRuleProcessor){
                        with(myElement){
                            myFoundElements.push(myElement);
                        }
                    return true;
                    }
                }

                 

                 

                Kasyan

                • 5. Re: What is the purpose of...
                  jpedroza2kLDS Level 1

                  Thanks! This gives me a perfect starting point to get me where I need to be with this script. I will try and remember to post the solution I come up with.

                   

                  Cheers,

                   

                  Jared