XML

The datatype for handling XML data in VL is called XElement.

In the nodebrowser explore the category System.XML to get an overview of all the nodes available for operating on XElements.

The examples on this page refer to the following XML structure:

<?xml version="1.0" encoding="UTF-8"?>
<entries>
  <entry visible="true" >
    <id>1</id>
    <label>Foo</label>
    <description>A Thing</description>
    <speed>2.4</speed>
  </entry>
  <entry visible="false">
    <id>2</id>
    <label>Bar</label>
    <description>Another Thing</description>
    <speed>4.2</speed>
  </entry>
</entries>

Extracting data from an XElement using XPath queries

General information about XPath can be found at W3CSchools: XML and XPath

Each XElement can have:

  • a value

  • a list of XAttributes

  • a list of child XElements

Referring to the example above:

  • the value of the first "label" element is "Foo"

  • the element "entry" has one attribute with the name "visible". the value of the first entries "visible" attribute is "true"

  • the child elements of the "entry" element are: "id", "label", "description" and "position"

Accessing an elements value

To access the value of only the first occurrence of an element, use the XPathGetValue [System.XML] node:

..\..\images\xml 1a41f.png
Figure 1. The first XPathGetValue node is grayed out (ie. not in use), because it does not yet have anything connected to its output. The second node has an IOBox connected that is configured to type 'String' which tells the XPathGetValue node to interpret the XElements value as a string

To get the values of all occurrences of an element, use the XPathGetValues [System.XML] node:

..\..\images\xml a7e85.png
Figure 2. XPathGetValues returns the values of all queried elements as spread of whatever type is connected

Accessing an elements attributes

To access an attribute of only the first occurrence of an element, use the XPathGetAttributeValue [System.XML] node:

..\..\images\xml cc084.png
Figure 3. The first XPathGetAttributeValue node is grayed out (ie. not in use), because it does not yet have anything connected to its output. The second node has an IOBox connected that is configured to type 'Boolean' which tells the XPathGetAttributeValue node to interpret the XElements value as a boolean

To get the attributes of all occurrences of an element, use the XPathGetAttributeValues [System.XML] node:

..\..\images\xml 028d5.png
Figure 4. XPathGetAttributeValues returns the values of all queried attributes as spread of whatever type is connected

results matching ""

    No results matching ""