Four Stars

Problem with XPath query (pick value based on attribute in multi element)

Hi All;

I'm facing problem with XPath query in tFileInputXML, when I'm using query with element number defined:

/Tracks/SegmentTrack[1]/Value

 

It is working but when I use conditional:

/Tracks/SegmentTrack[Value/@type='magnetic']/Value

 

It returns null, I've tried with \" instead of ', but still same result. I've tested query online and it is working correctly, site used:

https://www.freeformatter.com/xpath-tester.html#ad-output

 

Am I doing something wrong or this kind of queries are not supported?

If not supported, do you have any suggestion without heavy string parsing?

 

 

 

All suggestions really appreciated.

Thank you very much

BR/Artur

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: Problem with XPath query (pick value based on attribute in multi element)

@GnuS,check the txmlinput settings,since i was able to get wth belowUntitled.pngUntitled.png.

 

Manohar B
5 REPLIES
Twelve Stars

Re: Problem with XPath query (pick value based on attribute in multi element)

@GnuS,try with below one should reslove.

 

"/Tracks/SegmentTrack[Value/@type='magnetic']"

Manohar B
Four Stars

Re: Problem with XPath query (pick value based on attribute in multi element)

Hi;

@manodwhb It is same, NULL, besides the fact that I need Value not whole element.

 

BR/Artur

Twelve Stars

Re: Problem with XPath query (pick value based on attribute in multi element)

@GnuS,check the txmlinput settings,since i was able to get wth belowUntitled.pngUntitled.png.

 

Manohar B
Four Stars

Re: Problem with XPath query (pick value based on attribute in multi element)

Hi;

I have to dig a bit more but you are correct it is working (real XML is bigger and cannot share it).

 

Thank you very much for your time and help.

 

BR/Artur

Four Stars

Re: Problem with XPath query (pick value based on attribute in multi element)

Hi All;

I hope it will be helpful for somebody, I've found the reason of my problem, XML which I'm parsing is actually double loop (example was a cut), my loop is on LEVEL_A because I want to have records per it, and searching on SegmentTrack will not work, it will simply pickup first one, that's it and will not iterate through others to find needed record. What is confusing is that online parsers does work on second loop searches. Below XML with representation of my XML.

 

 <LEVEL_As>

  <LEVEL_A seq=1>

 <Tracks>
   <SegmentTrack>
   <Value type="true" unit="deg">341</Value>
   </SegmentTrack>
   <SegmentTrack>
   <Value type="magnetic" unit="deg">338</Value>
   </SegmentTrack>
   </Tracks>   

  </LEVEL_A>

<Tracks>
   <SegmentTrack>
   <Value type="true" unit="deg">341</Value>
   </SegmentTrack>
   <SegmentTrack>
   <Value type="magnetic" unit="deg">338</Value>
   </SegmentTrack>
   </Tracks>   

  <LEVEL_A seq=2>

  </LEVEL_A>

...

  <LEVEL_A seq=N>

<Tracks>
   <SegmentTrack>
   <Value type="true" unit="deg">341</Value>
   </SegmentTrack>
   <SegmentTrack>
   <Value type="magnetic" unit="deg">338</Value>
   </SegmentTrack>
   </Tracks>   

  </LEVEL_A>

 </LEVEL_As>