LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XML Parser - Child Position

What I get from OP is that the "position" text in the XML (quite confusing) is just a temporary thing.

 

The question (AFAIK) is how to get the position without the text, with an XPath query.

0 Kudos
Message 11 of 21
(759 Views)

@Wiebe, this is also my understanding that the position text in the comment node is a temporary thing. I just realise that the paragraph explaining the code did not shows (I had problem with the quote button not showing anything prior so probably related to that).

 

My code doesn't use the "position" text, it uses the XPATH position() function.

 

The strategy is to get to the target node using the Name attribute (e.g. step112) and then to get a reference to the parent node of that target node. From there I use the xpath position() function in a while loop to iterate throughout the child node of the parent node until I reach the target node.

 

TABLE[position()=1] returns the first child, TABLE[position()=2] returns the 2nd child, ...

 

I added a TABLES (with an S) root node to the XML to insure that all the TABLE node have a parent node.

 

I left the comments with the "position" text to be able to validate the results.

 

Ben64

0 Kudos
Message 12 of 21
(754 Views)

Hi @ben64, when I surfing on intenet, I found the same expression that you have in the code "count(a/b[.='tsr']/preceding-sibling::*)+1", but I don't know how to use it in LabVIEW.

0 Kudos
Message 13 of 21
(753 Views)

@dgd.gomez, you can't use this in LabVIEW. It for another type of XML (DirXML if I remember) that is more related to stylesheet.

 

Ben64

0 Kudos
Message 14 of 21
(749 Views)

@ben64 wrote:

@Wiebe, this is also my understanding that the position text in the comment node is a temporary thing. I just realise that the paragraph explaining the code did not shows (I had problem with the quote button not showing anything prior so probably related to that).

 

My code doesn't use the "position" text, it uses the XPATH position() function.


😐🌴 (:face palm:). Like I said, confusing.

 

0 Kudos
Message 15 of 21
(741 Views)

@dgd.gomez wrote:

Hi @ben64, when I surfing on intenet, I found the same expression that you have in the code "count(a/b[.='tsr']/preceding-sibling::*)+1", but I don't know how to use it in LabVIEW.


Found that one too. "count" is included in the XPath standard (see this, (counting elements)).

 

It doesn't work in LabVIEW, but I think that is because the XPath implementation LabVIEW uses isn't complete or old.

0 Kudos
Message 16 of 21
(737 Views)

The XPATH implementation in LabVIEW is only valid for location path.

 

Ben64

0 Kudos
Message 17 of 21
(727 Views)

@ben64 wrote:

The XPATH implementation in LabVIEW is only valid for location path.


The help says it implements XPath version 1.0. XPath currently is version 3.1...

 

V1.0 does include count, and it's not working, so there seem to be other limitations. It there any reference to these limitations?

0 Kudos
Message 18 of 21
(720 Views)

BTW. my solution would be to switch XML library. LV's native XML lib is slow and not up to date.

 

I'd look around a bit on the forum, but here's one alternative.

0 Kudos
Message 19 of 21
(719 Views)

I don't think there is a reference to the limitations. It's just that the only VIs using XPath are the First Match Node.vi and Get All Match Node.vi. Using an xpath expression that is not a location path with these vis will throw error -2769: The XPath expression must be a location path.

 

Ben64

0 Kudos
Message 20 of 21
(717 Views)