2 Replies Latest reply on May 10, 2018 11:44 PM by Ronald63

    [xpath] Selecting Several Paths

    Ronald63 Level 4



      I want select several path in Xml with XPath expression. I try to use | operator but without success.

      Thanks for your help.


      var s = '<Root>';;
      s += '<TAG1>t1</TAG1>';
      s += '<TAG2>i1</TAG2>';
      s += '<TAG3>tag_3_value</TAG3>';
      s += '<TAG1>t2</TAG1>';
      s += '<TAG2>i2</TAG2>';
      s += '<TAG4>tag_4_value</TAG4>';
      s += '<TAG1>t3</TAG1>';
      s += '<TAG2>i3</TAG2>';
      s += '</Root>';
      var x = new XML (s);
      var p0 = x.xpath('//TAG3'); // return 'tag_3_value'
      var p1 = x.xpath('//TAG3|//TAG4'); // return nothing
      var p2 = x.xpath('//(TAG3|TAG4)'); // syntax error



        • 1. Re: [xpath] Selecting Several Paths
          Loic.Aigon Adobe Community Professional



          First of all, you don't need to instantiate an XML object passing by a XML string. E4X allows you to declare XML as Objects:


          var xmlObject = <Root>  


          Second of all, you need to take a serious look at XPath even if its implementation is not fully completed in ExtendScript:


          //E4X approach for retrieving TAG2 & TAG3
          xmlObject.*.(/TAG[23]/.test(name()) );
          //or using xpath
          xmlObject.xpath( "//*[local-name()='TAG2' or local-name()='TAG3']" );




          • 2. Re: [xpath] Selecting Several Paths
            Ronald63 Level 4

            Hi Loic,


            Thank you for your help ;-)


            Bonne journée