03-08-2017 02:43 PM
Dear Community,
I am trying to read an xml Data of the form:
<Signal_ID_1>
<Value> 5 </Value>
<Info> Info </Info>
<Signal_ID_ 2>
<Value> 3 </Value>
<Info> Info </Info>
...etc.
I have tried to solve this as shown in the snippet. This does not quite work yet. I know I should be giving more details about my problem but maybe someone already has some some hints for a solution.
Gratefully
03-08-2017 04:43 PM
First one - For loop index starts from 0, file - from Signal_ID_1
Error message would be usefull.
03-09-2017 06:41 AM
Hi Labviewette,
Is there nothin else within the xml-file? Could you upload an example-file? Then I could give it a try and provide you with the code needed. By the way, the VI "Extract XML Data.vi" seems to be a self-written subVI, and not part of the vi.lib, so the snippet isnt executable without the VI.
You can upload the SubVI as well, but I think an example-XML will do!
Best,
Jan Göbel
Staff Applications Engineer
National Instruments
03-09-2017 01:28 PM
@labviewette wrote:
Dear Community,
I am trying to read an xml Data of the form:
<Signal_ID_1>
<Value> 5 </Value>
<Info> Info </Info>
<Signal_ID_ 2>
<Value> 3 </Value>
<Info> Info </Info>
...etc.
I have tried to solve this as shown in the snippet. This does not quite work yet. I know I should be giving more details about my problem but maybe someone already has some some hints for a solution.
Gratefully
I don't know what your XML file looks like but if the elements you put are copy pasted from your file there are issues in it. First, we don't know if your file has a root node. Then <Signal_ID_1> and <Signal_ID_2> are missing closing tags.
Additionally this is not a very good structure, in your code you have a constant wired to the N terminal of the FOR loop meaning you need to know how many signals exist (you could always use a while loop until you get an error). Now if you delete a signal you need to reassign the ID because you look sequentially at the value of Signal_ID_X in your code. In my opinion ID should be a child node of Signal (or an attribute). I would suggest using a structure like this:
<Signals>
<Signal>
<ID> 1 </ID>
<Value> 5 </Value>
<Info> Info1 </Info>
<Channel> 101 </Channel>
</Signal>
<Signal>
<ID> 2 </ID>
<Value> 3 </Value>
<Info> Info2 </Info>
<Channel> 102 </Channel>
</Signal>
<Signal>
<ID> 3 </ID>
<Value> 8 </Value>
<Info> Info3 </Info>
<Channel> 105 </Channel>
</Signal>
</Signals>
Here every signal is a child of the Signals node and you can use Get All Matched Nodes.vi with the following xpath expression "//Signal" (without the double quote) to get an array of node reference that you can use to auto-index a FOR loop to get the content of each signal. You would then be able to add and remove signals from your file without changing the code.
Ben64
03-09-2017 03:10 PM
Thank you Alexander_Sobolev, JGoebel, and Ben64 for your time and effort. I took the time to figure my problem out.
I have attached xml, and the VIs (LV2015).
The problem I was facing was that I was connecting my root node (in this case "IO") to the tag name of the invoke node "Get Elements By Tag Name" because of my misconception that this is the first step in order to read the child nodes...
Another thing learnd today !