XML overview
- Last UpdatedNov 03, 2022
- 2 minute read
- PI System
- PI Interface for DNP3 3.3.1.38
- Interfaces
XML follows a similar pattern to HTML. The structure used by both languages is described as being tree-like. This is because the structure branches in many different directions, where each branch may contain other branches. Angle brackets, <>, are used to specify the beginning and end of a node. The beginning of a node looks like <node> and the end as </node> . There must be a beginning and end to every node. The first node of an XML document is referred to as the root node. Nodes that are contained between the opening and closing of a node are called child nodes. The parameters surrounded by square brackets [ ] are optional:
<node [attributename="value"]>
<child [attributename="value"]>
</child>
</node>
Each node has a name associated with it. In the example above, the name of the root node would be node and the name of the child element would be child.
Nodes can also have attributes. The format for an attribute has the following layout.
AttributeName ="AttributeValue"
The attribute value is always enclosed in quotations and is treated internally as a string but can be converted to any other data type. An attribute looks like the following.
<node Attribute="2"></node>
The value of this Attribute is 2. A node can also have elements. Elements appear the same as nodes, except that they have loose text between the opening and closing of the node. The value of the element is treated internally as a string but can be converted to any other data type. Unlike an attribute value, an element value is not enclosed in quotations.
An example of an element is shown below.
<node Attribute="2">
<child ID="1">
<Element>myText</Element>
<child ID="2">
<Element>myText</Element>
</child>
</child>
</node>
In the example above, the element of the first child is the string myText. Note that child nodes can contain other child nodes, thus, forming the tree structure. The second child nodes element has 3 as its text value.
The short form of a node that has no child nodes or elements appears in the following form.
<Name Attributes… />
This format does not require a closing node. It only requires the opening node as long as it ends with a forward slash.