Copy link to clipboard
Copied
Hi,
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'
$.writeln(p0)
var p1 = x.xpath('//TAG3|//TAG4'); // return nothing
$.writeln(p1)
var p2 = x.xpath('//(TAG3|TAG4)'); // syntax error
Ronald
Hi,
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>
<TAG1>t1</TAG1>
<TAG2>i1</TAG2>
<TAG3>tag_3_value</TAG3>
<TAG1>t2</TAG1>
<TAG2>i2</TAG2>
<TAG4>tag_4_value</TAG4>
<TAG1>t3</TAG1>
<TAG2>i3</TAG2>
</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]/.tes
Copy link to clipboard
Copied
Hi,
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>
<TAG1>t1</TAG1>
<TAG2>i1</TAG2>
<TAG3>tag_3_value</TAG3>
<TAG1>t2</TAG1>
<TAG2>i2</TAG2>
<TAG4>tag_4_value</TAG4>
<TAG1>t3</TAG1>
<TAG2>i3</TAG2>
</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']" );
HTH
Loic
Copy link to clipboard
Copied
Hi Loic,
Thank you for your help 😉
Bonne journée
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more