LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XML Parser - Child Position

Hi, I am using XML Parser, and I need to know the position of a child, Is it possible?

 

I have tried with native nodes and using XPath expressions, but I have not succeded. Does anybody have an idea?

 

Thank a lot.

0 Kudos
Message 1 of 21
(3,744 Views)

Use XPath to get nodes, then use Previous Sibling until it returns an error.

 

This will return 1, 3, 5, 8 (Array). You might expect 0, 1, 2, 3, but sadly XML isn't that easy. Text nodes (the \r\n) are siblings too, and are counted. You can keep count selectively, counting only elements (Array 2):

 

XML Child Index.png

 

But if you get the Nth child, text childs are included.

 

Not sure how performant this is. But if there where a method for this, it would probably do the same.

0 Kudos
Message 2 of 21
(3,729 Views)

Also, you can do this recursively for each level. Get the child index, try to get the parent node, until this gives an array. This will give an array of indices, one for each level.

 

EDIT: Of course, it's recommended you put these functions in subVIs...

0 Kudos
Message 3 of 21
(3,727 Views)

Hi wiebe@CARYA, thank a lot for the answer.

 

Please, check the following example:

 

Image1.PNG

 

My intention is to be able to obtain position of the child, to avoid errors when editing the XML code.

 

Thank a lot. I hope it is clarifying.

0 Kudos
Message 4 of 21
(3,694 Views)

I wouldn't have guested that...

 

So, problem solved? 

0 Kudos
Message 5 of 21
(3,687 Views)

No, the XML code shown in the example is very small, when the XML code increases, it becomes impossible to maintain this.

 

The index I need matches the postion index of each child. The question is: Is it possible to get this value using nodes or XPath?

 

Thank a lot.

0 Kudos
Message 6 of 21
(3,684 Views)

@dgd.gomez wrote:

No, the XML code shown in the example is very small, when the XML code increases, it becomes impossible to maintain this.

 

The index I need matches the postion index of each child. The question is: Is it possible to get this value using nodes or XPath?


I don't think so.

 

You can get the position from a XPath result (as I showed earlier).

 

Or, get all childs (or tables) and iterate over them. The 'i' will be the index.

0 Kudos
Message 7 of 21
(3,676 Views)

"Or, get all childs (or tables) and iterate over them. The 'i' will be the index."

 

 

0 Kudos
Message 8 of 21
(3,647 Views)

Sorry, I still working with LV2017.

0 Kudos
Message 9 of 21
(3,641 Views)

Attached version 2017.

 

Ben64

0 Kudos
Message 10 of 21
(3,636 Views)