XMLNodes

An XMLNode has 6 members known respectively as: #content, #attribs, #namespace, #control, #cdata and #comment. If an XML tag has child tags, then they are represented as additional members of the structure.

For example, given the following XML code:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Simple XML to do a test for well-formedness -->
<catalog>
  <book id="book42">
    <author>Pomeroy, Steve</author>
    <title>RPC Manual</title>
    <genre>SCADA Software</genre>
  </book>
</catalog>

This would be represented in VTScada by the following XMLNode structure:

The fact that the #content member is at subscript [0] enables script code to take advantage of automatic subscription into arrays, to refer to the #content member of any node just by specifying the node. For example, to access the book title, assuming the XMLNode tree is held in variable "XMLNodes", use the following code:

XMLNode\catalog\book\title

All other members can be accessed via Scope():

Scope(XMLNode\catalog\book, "#attribs")

Both these constructs can be used on either side of an assignment.

The purpose of the 6 standard members of the structure are as follows:

Member Name

Purpose

#content

The textual content of the tag.

#attribs

A dictionary containing the attributes of the tag.

#namespace

A string representing the namespace the tag belongs to.

#control

An internal use field. Used by XMLWrite to spot loops.

#cdata

A string representing any CDATA associated with the tag.

#comment

A string representing a comment associated with the tag.

All members can be both read from and written to, but note that the #control member will be altered by XMLWrite() when processing the XMLNode tree. As each node is visited, the #control member is set to a unique value for that call to XMLWrite(). If a node already has the unique value when visited then a loop has been found and writing terminates at that point. An error is returned.

Accessing a portion of an XMLNode tree.

Take care when writing code to access a portion of an XMLNode tree. You should use either the address-of operator (&) to pass a pointer, or use XMLGetNode() to extract the node of interest:

MySub(&(XMLNode\catalog\book));

or

MySub(XMLGetNode(XMLNode\catalog\book);

Note that the first version will require the use of the dereference (*) operator on every access.