• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[xpath] Selecting Several Paths

Enthusiast ,
May 10, 2018 May 10, 2018

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

TOPICS
Scripting

Views

729

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , May 10, 2018 May 10, 2018

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

...

Votes

Translate

Translate
People's Champ ,
May 10, 2018 May 10, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

LATEST

Hi Loic,

Thank you for your help 😉

Bonne journée

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines