LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read attributes from XML

Hi, I need to read data from an XML file, but since I'm fairly new to Labview and XML, I could really use some help.

Below is the content of the XML (part of it)

 

I need to read the serial number and weight from resource "ID1" and "ID8".

 

<resource name="printer">

<resource name="ID1">

- <counters>
  <counter description="product number" name="48030" type="lifetime" value="11081034" />
  <counter description="Weight [g]" name="48031" type="lifetime" value="692" />
  <counter description="Warm hours [h]" name="48032" type="lifetime" value="1454" />
  </counters>
 

<resource name="ID8">

- <counters>
  <counter description="product number" name="48030" type="lifetime" value="11081042" />
  <counter description="Weight [g]" name="48031" type="lifetime" value="692" />
  <counter description="Warm hours [h]" name="48032" type="lifetime" value="1454" />
  </counters>
 
</resource>
0 Kudos
Message 1 of 18
(8,530 Views)

Why don't you try using Easy XML toolkit.

 

Its Demo version is free. 🙂

0 Kudos
Message 2 of 18
(8,514 Views)

Here's a way to do it using the LabVIEW XML Parser functions.

 

Ben64

 

Read attributes from XML.png

Message 3 of 18
(8,502 Views)

Hi, thanks for the replies.

 

I started out with putting all data in an array, but it is simply to complex.

I had a look at EasyXML and it looks very promessing, but I can someone please help me with creating a cluster for the above mentioned XML?

 

 

Thanks,

0 Kudos
Message 4 of 18
(8,477 Views)

Here is how to use the JKI Easy XML functions to convert between clusters and XML strings.

 

Ben64

 

Using Easy XML.png

Message 5 of 18
(8,462 Views)

Thank you Ben, it was very helpful.

How'd you use the Easy XML to convert from XML to cluster or array of clusters for the same example?


Kudos are the best way to say thanks 🙂
0 Kudos
Message 6 of 18
(8,402 Views)

Hi,

 Refer to example:

"<LabVIEW>\examples\JKI\EasyXML" .

 

Also you can get complete documetation for the same here

if you need to create parse data from XML you'll need to create the custer control (or constant as i do in the example in link given below) then parse the data from the XML to the output cluster.

 

I have created the code for your XML data here in dropbox (unable to attach VI on this forum due to error)

Message 7 of 18
(8,386 Views)

When you paste the XML code it into the string control, the resulting cluster is not populated correctly.

Also, would the behavior be the same if I create an array of clusters for counter?


Kudos are the best way to say thanks 🙂
Message 8 of 18
(8,373 Views)

It helped a lot, getting all the attributes from a file

 

Thanks

0 Kudos
Message 9 of 18
(7,172 Views)

Could you please explain why you gave //*@ as the string constant to get all matched nodes

thanks in advance 

Anil

0 Kudos
Message 10 of 18
(6,473 Views)