LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ParseXMLFragments doesn't parse XML tags containing attributes

Hi,

After analyzing the VI's of the "Getting Started Window" I feel impressed and want to integrate a XML storage for my next application. Currently I'm responsible for a list of computers which are still hold inside a XML file. At the moment I have to edit this file manually which is quiet boring when seeing the features of LabVIEW. So I tried to parse the contained data with the ParseXMLFragments.vi and recognized a strange behavior.

Every computer is mapped as an element and contains an attribute "id" with an uniform identifier. Running the parser on that data doesn't produce the expected result. Instead of getting a list of computers the elements with attributes result in two new entries for configuration and management. See the reduced testcase below or the attached VI for LV8.2:

The XML data

<computer id="office034">
    <configuration>
      <cpu clock="2.6 GHz">Intel(R) Celeron</cpu>
    </configuration>

    <management>
      <investment>81732646</investment>
    </management>
</computer>


is parsed in an array with two elements:

    <configuration>
      <cpu clock="2.6 GHz">Intel(R) Celeron</cpu>
    </configuration>
   -----------------------------------------------------
    <management>
      <investment>81732646</investment>
    </management>

This is not the expected result. Parsing the element computer should return the same data. If you remove the attribute from the elements it's working well.

Is this a known bug for the ParseXMLFragments.vi and is there any simple workaround available?

Thanks
Henrik
0 Kudos
Message 1 of 5
(3,450 Views)

Hi,

I think the Tag must close with the same name with which it is opened.
Then the vi does what its description mentions: Parsing the high level tags into an array from which u can read each one.

<computer id="office034">
    <configuration>
      <cpu clock="2.6 GHz">Intel(R) Celeron</cpu>
    </configuration>

    <management>
      <investment>81732646</investment>
    </management>
</computer>        <--- != 
<computer id="office034">


greetings Marco B. NIG
0 Kudos
Message 2 of 5
(3,427 Views)
No, that's not the right way. Any attribute inside a start tag doesn't have to be taken into account. Only the first part just right before the first whitespace has to be used as start tag. Please read the W3C recommendation which describes how to handle start and end tags. Any other way will destroy my well-formed XML structure.

http://www.w3.org/TR/1998/REC-xml-19980210#sec-starttags

Further empty element tags are also not recognized by the parser. They only have a start tag with a trailing slash inside. There is no end tag. For example use the following img tag:

<img src="background.jpg" />

This results in an empty array for the returned value.
0 Kudos
Message 3 of 5
(3,412 Views)

Hi ,

Yes you are right, and I observed the behaviour too.
I reported it to our R&D.
Hopefully it will be fixed in the next LV-Version, that´s all I can say about that.


regards

Marco B


0 Kudos
Message 4 of 5
(3,400 Views)
I apologize if my example misled you. For performance reasons, the Getting Started window uses a simple parser that does not implement full XML parsing.

There are other options for using XML in LabVIEW. The Internet toolkit includes XML VIs which utilize the Xerces parser. You could also use an ActiveX interface to Microsoft's MSXML.

- Christina

Christina Rogers
Principal Product Owner, LabVIEW R&D
0 Kudos
Message 5 of 5
(3,378 Views)