4 Replies Latest reply on May 26, 2010 11:31 PM by Kasyan Servetsky

    How to find decendent xml element (ID CS4)

    gopaljay78 Level 1

      Hi,

       

      I have the following xml structure in Indesign document.

      <X>

           <A>

                <B>

                     <C>  </C>

                </B>

           </A>

       

           <E>

                <F>

                     <C>  </C>

                </F>

           </E>

       

           <B>

                <C>  </C>

           </B>

      </X>

       

      I want to find the xml element <C> under <B> tag only. Can anybody suggest me how to get this.

       

      Thanks,

      Gopal

        • 1. Re: How to find decendent xml element (ID CS4)
          PankChat Level 1

          Look Into the XMLRules.

           

           

           

          I have the following xml structure in Indesign document.

           

          </X

          • 2. Re: How to find decendent xml element (ID CS4)
            Kasyan Servetsky Level 5
            #target indesign
            #include "/Applications/Adobe InDesign CS3/Scripts/Xml Rules/glue code.jsx"
            
            var myDocument = app.activeDocument;
            var myCounter = 0;
            
            var myRuleSet = new Array (new ProcessProduct);
            
            with(myDocument){
                var elements = xmlElements;
                __processRuleSet(elements.item(0), myRuleSet);
            }
            
            alert("Found " + myCounter + " \"C\" elements under \"B\" element");
            
            function ProcessProduct(){
                this.name = "ProcessElements";
                this.xpath = "//B/C";   
                this.apply = function(myElement, myRuleProcessor){
                    with(myElement){
                        myCounter++;
                    }
                return true;
                }
            }
            
            • 3. Re: How to find decendent xml element (ID CS4)
              PankChat Level 1

              Apology for bu** in, but my general practice (or for that matter mentioned scripting manual) is that

               

              function ProcessProduct(){

                  this.name = "ProcessElements";

                  this.xpath = "//B/C"; 

               

               

              should be

               

              function ProcessProduct(){

                  this.name = "ProcessProduct";

                  this.xpath = "//B/C"; 

               

               

               

                

              name of the rule and matches the

              RuleName,but both of them seems to be working fine here.

               

              Defining correctly in ruleset does the trick

               

              var myRuleSet = new Array (new ProcessProduct);

               

              Does it not matter for having the same name or I am missing something.

               

              --PC

               

              • 4. Re: How to find decendent xml element (ID CS4)
                Kasyan Servetsky Level 5

                Yes, I agree with you — I just modified an example I posted long ago on this forum and failed to rename the function, although it works this way too.That's what happens when my left eye looks at one computer where I am making color correction, and my right eye reads scripting forum on another.

                 

                Kasyan