Class

# XMLNode

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

XMLNode is the base class for most of the XML Document Object Model (DOM) classes and implements many of the common properties and functions of a DOM node. This class won't usually be instantiated directly. Most objects will be created from methods of the `XMLDocument</api/text/xml/xmldocument>` class.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                       | Type                                     | Read-Only | Shared |
|--------------------------------------------|------------------------------------------|-----------|--------|
| `AttributeCount<xmlnode.attributecount>`   | `Integer</api/data_types/integer>`       | ✓         |        |
| `ChildCount<xmlnode.childcount>`           | `Integer</api/data_types/integer>`       | ✓         |        |
| `FirstChild<xmlnode.firstchild>`           | XMLNode                                  | ✓         |        |
| `LastChild<xmlnode.lastchild>`             | XMLNode                                  | ✓         |        |
| `LastError<xmlnode.lasterror>`             | `Integer</api/data_types/integer>`       | ✓         |        |
| `LocalName<xmlnode.localname>`             | `String</api/data_types/string>`         | ✓         |        |
| `Name<xmlnode.name>`                       | `String</api/data_types/string>`         |           |        |
| `NamespaceURI<xmlnode.namespaceuri>`       | `String</api/data_types/string>`         | ✓         |        |
| `NextSibling<xmlnode.nextsibling>`         | XMLNode                                  | ✓         |        |
| `OwnerDocument<xmlnode.ownerdocument>`     | `XMLDocument</api/text/xml/xmldocument>` | ✓         |        |
| `Parent<xmlnode.parent>`                   | XMLNode                                  | ✓         |        |
| `Prefix<xmlnode.prefix>`                   | `String</api/data_types/string>`         | ✓         |        |
| `PreviousSibling<xmlnode.previoussibling>` | XMLNode                                  | ✓         |        |
| `ToString<xmlnode.tostring>`               | `String</api/data_types/string>`         | ✓         |        |
| `Type<xmlnode.type>`                       | `Integer</api/data_types/integer>`       | ✓         |        |
| `Value<xmlnode.value>`                     | `String</api/data_types/string>`         |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                               | Parameters                                                                                                                   | Returns                                    | Shared |
|----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|--------|
| `AppendChild<xmlnode.appendchild>`                 | newChild As XMLNode                                                                                                          | XMLNode                                    |        |
| `Child<xmlnode.child>`                             | index As `Integer</api/data_types/integer>`                                                                                  | XMLNode                                    |        |
| `Clone<xmlnode.clone>`                             | deep As `Boolean</api/data_types/boolean>`                                                                                   | XMLNode                                    |        |
| `Compare<xmlnode.compare>`                         | node As XMLNode                                                                                                              | `Integer</api/data_types/integer>`         |        |
| `GetAttribute<xmlnode.getattribute>`               | name As `String</api/data_types/string>`                                                                                     | `String</api/data_types/string>`           |        |
|                                                    | uri As `String</api/data_types/string>`, name As `String</api/data_types/string>`                                            | `String</api/data_types/string>`           |        |
| `GetAttributeNode<xmlnode.getattributenode>`       | index As `Integer</api/data_types/integer>`                                                                                  | `XMLAttribute</api/text/xml/xmlattribute>` |        |
|                                                    | name As `String</api/data_types/string>`                                                                                     | `XMLAttribute</api/text/xml/xmlattribute>` |        |
|                                                    | uri As `String</api/data_types/string>`, name As `String</api/data_types/string>`                                            | `XMLAttribute</api/text/xml/xmlattribute>` |        |
| `Insert<xmlnode.insert>`                           | newChild As XMLNode, beforeChild As XMLNode                                                                                  | XMLNode                                    |        |
| `RemoveAttribute<xmlnode.removeattribute>`         | name As `String</api/data_types/string>`                                                                                     |                                            |        |
| `RemoveAttributeNode<xmlnode.removeattributenode>` | attributeNode As `XMLAttribute</api/text/xml/xmlattribute>`                                                                  | `XMLAttribute</api/text/xml/xmlattribute>` |        |
| `RemoveChild<xmlnode.removechild>`                 | oldChild As XMLNode                                                                                                          |                                            |        |
| `ReplaceChild<xmlnode.replacechild>`               | newChild As XMLNode, oldChild As XMLNode                                                                                     | XMLNode                                    |        |
| `SetAttribute<xmlnode.setattribute>`               | name As `String</api/data_types/string>`, value As `String</api/data_types/string>`                                          |                                            |        |
|                                                    | uri As `String</api/data_types/string>`, name As `String</api/data_types/string>`, value As `String</api/data_types/string>` |                                            |        |
| `SetAttributeNode<xmlnode.setattributenode>`       | attributeNode As `XMLAttribute</api/text/xml/xmlattribute>`                                                                  | `XMLAttribute</api/text/xml/xmlattribute>` |        |
|                                                    | attributeNode As `XMLAttribute</api/text/xml/xmlattribute>`                                                                  |                                            |        |
| `XQL<xmlnode.xql>`                                 | query As `String</api/data_types/string>`                                                                                    | `XMLNodeList</api/text/xml/xmlnodelist>`   |        |
|                                                    | query As `String</api/data_types/string>`, map() As `String</api/data_types/string>`                                         | `XMLNodeList</api/text/xml/xmlnodelist>`   |        |

## Property descriptions

<div id="xmlnode.attributecount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.AttributeCount

**AttributeCount** As `Integer</api/data_types/integer>`

> The number of attributes this element contains.
>
> This property is read-only.

<div id="xmlnode.childcount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.ChildCount

**ChildCount** As `Integer</api/data_types/integer>`

> The number of child nodes contained by this node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example displays the number of teams in the above XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
> MessageBox("Teams in League: " + xml.DocumentElement.ChildCount.ToString)
> ```

<div id="xmlnode.firstchild">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.FirstChild

**FirstChild** As **XMLNode**

> The first child of this node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example displays the first Team in the League XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> MessageBox("First Team in League: " + xml.DocumentElement.FirstChild.GetAttribute("name"))
> ```

<div id="xmlnode.lastchild">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.LastChild

**LastChild** As **XMLNode**

> The first child of this node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example displays the last team in the League XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> MessageBox("Last Team in League: " + xml.DocumentElement.LastChild.GetAttribute("name"))
> ```

<div id="xmlnode.lasterror">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.LastError

**LastError** As `Integer</api/data_types/integer>`

> Contains an error code after an `XMLException</api/exceptions/xmlexception>` occurs.
>
> This property is read-only.
>
> XMLNodeList.Item will specify an error code if the item could not be created, and XMLNodeList.ToString could as well.
>
> | Error Code | Description             |
> |------------|-------------------------|
> | 0          | No error occurred.      |
> | 1          | Index size error        |
> | 2          | DOM String size error   |
> | 3          | Hierarchy request error |
> | 4          | Wrong document          |
> | 5          | Invalid character       |
> | 6          | No data allowed         |
> | 7          | No modification allowed |
> | 8          | Not found               |
> | 9          | Not supported           |
> | 10         | In use attribute        |
> | 11         | Invalid state           |
> | 12         | Syntax error            |
> | 13         | Invalid modification    |
> | 14         | Namespace error         |
> | 15         | Invalid access          |
> | 16         | Invalid node type       |
> | 17         | Query parse error       |
> | 18         | Query execution error   |
> | 19         | Not OK                  |

<div id="xmlnode.localname">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.LocalName

**LocalName** As `String</api/data_types/string>`

> The name of the node without the prefix.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example displays the name of the root node in the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> MessageBox("LocalName of root node: " + xml.DocumentElement.LocalName) ' League
> ```

<div id="xmlnode.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Name

**Name** As `String</api/data_types/string>`

> The name of this node.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example displays the name of the root node in the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> MessageBox("Name of root node: " + xml.DocumentElement.Name) ' League
> ```
>
> This code changes the name of the root node from "League" to "AmericanLeague":
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> xml.DocumentElement.Name = "AmericanLeague"
>
> MessageBox("Name of root node: " + xml.DocumentElement.Name) ' AmericanLeague
> ```

<div id="xmlnode.namespaceuri">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.NamespaceURI

**NamespaceURI** As `String</api/data_types/string>`

> The namespaceURI of this node.
>
> This property is read-only.

<div id="xmlnode.nextsibling">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.NextSibling

**NextSibling** As **XMLNode**

> The next node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example shows how to walk over the team nodes in the above XML and displays each team name:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> While n <> Nil
>   MessageBox(n.Name + ": " + n.GetAttribute("name"))
>   n = n.NextSibling
> Wend
> ```

<div id="xmlnode.ownerdocument">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.OwnerDocument

**OwnerDocument** As `XMLDocument</api/text/xml/xmldocument>`

> The XMLDocument that contains this node.
>
> Use this property to get a reference to the XMLDocument that you can then use with the various "Create" methods to add new items to the XML. This is useful when you have access to an <span class="title-ref">XMLNode</span>, but no longer have a reference to the XMLDocument that contains it.
>
> This property is read-only.

<div id="xmlnode.parent">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Parent

**Parent** As **XMLNode**

> The parent of this node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example displays the parent of the last team in the above XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.LastChild
>
> If n <> Nil Then
>   MessageBox("Name of " + n.Name + " node: " + n.Parent.Name)
> End If
> ```

<div id="xmlnode.prefix">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Prefix

**Prefix** As `String</api/data_types/string>`

> The namespace prefix of this node.
>
> This property is read-only.

<div id="xmlnode.previoussibling">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.PreviousSibling

**PreviousSibling** As **XMLNode**

> The preceding node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example shows how to walk in reverse over the team nodes in the above XML and displays each team name:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.LastChild
>
> While n <> Nil
>   MessageBox(n.Name + ": " + n.GetAttribute("name"))
>   n = n.PreviousSibling
> Wend
> ```

<div id="xmlnode.tostring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.ToString

**ToString** As `String</api/data_types/string>`

> A string representation of this node.
>
> This property is read-only.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Display the XML for the first team node:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> If n <> Nil Then
>   MessageBox("XML: " + n.ToString)
> End If
> ```

<div id="xmlnode.type">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Type

**Type** As `Integer</api/data_types/integer>`

> `Integer</api/data_types/integer>` constant denoting the type, such as Element, Attribute, TextNode, and so forth.
>
> Use the Class Constants of the `XMLNodeType</api/text/xml/xmlnodetype>` module to compare values.
>
> This property is read-only.

<div id="xmlnode.value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Value

**Value** As `String</api/data_types/string>`

> Used in some nodes to set or get the value, such as `XMLTextNode</api/text/xml/xmltextnode>` and `XMLAttribute</api/text/xml/xmlattribute>`.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> Not supported by all <span class="title-ref">XMLNode</span> subclasses.
>
> </div>

## Method descriptions

<div id="xmlnode.appendchild">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.AppendChild

**AppendChild**(newChild As XMLNode) As XMLNode

> Adds a child after the last child.
>
> Typically you will want to use the first syntax that returns an instance of the newly created child so that you can then attach information to the child.
>
> The following XML:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Can be created using this code, which displays the XML to a TextArea and prompts you to save it to a file:
>
> ``` Xojo
> Var xml As New XmlDocument
>
> Var root As XmlNode
> root = xml.AppendChild(xml.CreateElement("League"))
>
> Var teamNode As XmlNode
> Var playerNode As XmlNode
>
> ' Create 1st team and its players
> teamNode = root.AppendChild(xml.CreateElement("Team"))
> teamNode.SetAttribute("name", "Seagulls")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Bob")
> playerNode.SetAttribute("position", "1B")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Tom")
> playerNode.SetAttribute("position", "2B")
>
> ' Create 2nd team and its players
> teamNode = root.AppendChild(xml.CreateElement("Team"))
> teamNode.SetAttribute("name", "Pigeons")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Bill")
> playerNode.SetAttribute("position", "1B")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Tim")
> playerNode.SetAttribute("position", "2B")
>
> ' Create 3rd team and its players
> teamNode = root.AppendChild(xml.CreateElement("Team"))
> teamNode.SetAttribute("name", "Crows")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Ben")
> playerNode.SetAttribute("position", "1B")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Ty")
> playerNode.SetAttribute("position", "2B")
>
> TextArea1.Text = xml.ToString
>
> DisplayXML(xml)
> ```

<div id="xmlnode.child">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Child

**Child**(index As `Integer</api/data_types/integer>`) As XMLNode

> Returns the child <span class="title-ref">XMLNode</span> at the position denoted by *index*. *index* is zero-based.
>
> This example loads the following XML, contained in a constant called `kTestXml`, into a new XMLDocument and then displays the team names:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> ``` Xojo
> ' Load XML
> Var xml As New XmlDocument
> Try
>   xml.LoadXml(kTestXml)
> Catch e As XmlException
>   MessageBox("XML error: " + e.Message)
>   Return
> End Try
>
> For team As Integer = 0 To xml.DocumentElement.ChildCount-1
>   MessageBox("Team: " + xml.DocumentElement.Child(team).GetAttribute("name"))
> Next
> ```

<div id="xmlnode.clone">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Clone

**Clone**(deep As `Boolean</api/data_types/boolean>`) As XMLNode

> Duplicates the current node. The *deep* parameter indicates whether to also duplicate all the child nodes. It returns an <span class="title-ref">XMLNode</span>.
>
> The example code below uses this XML. Assign it to a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Duplicate the first team node, change the team name and add it to the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> If n <> Nil Then
>   ' Duplicate the first team
>   Var dup As XmlNode = n.Clone(True)
>
>   ' Change its name to "Eagles"
>   dup.SetAttribute("name", "Eagles")
>
>   ' Add it to the XmlDocument
>   n.Parent.AppendChild(dup)
>
>   TextArea1.Text = xml.ToString
> End If
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Eagles">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```

<div id="xmlnode.compare">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Compare

**Compare**(node As XMLNode) As `Integer</api/data_types/integer>`

> Compares two nodes, which must both have the same parent. Returns an Integer that works like `String.Compare<string.compare>`.
>
> The two nodes are compared using their string contents.
>
> - If <span class="title-ref">XMLNode</span> \< *node* it returns -1
> - If <span class="title-ref">XMLNode</span> = *node* it returns 0
> - If <span class="title-ref">XMLNode</span> \> *node* it returns 1
>
> If you need to compare nodes with different parents, use the `String.Compare<string.compare>` function on the `ToString<xmlnode.tostring>` value.

<div id="xmlnode.getattribute">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.GetAttribute

**GetAttribute**(name As `String</api/data_types/string>`) As `String</api/data_types/string>`

**GetAttribute**(uri As `String</api/data_types/string>`, name As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Gets the value of the attribute specified by *uri* and *name*.
>
> Returns "" (empty string) if the attribute does not exist.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example shows how to walk over the team nodes in the above XML and displays each team name:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> While n <> Nil
>   MessageBox(n.Name + ": " + n.GetAttribute("name"))
>   n = n.NextSibling
> Wend
> ```

<div id="xmlnode.getattributenode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.GetAttributeNode

**GetAttributeNode**(index As `Integer</api/data_types/integer>`) As `XMLAttribute</api/text/xml/xmlattribute>`

**GetAttributeNode**(name As `String</api/data_types/string>`) As `XMLAttribute</api/text/xml/xmlattribute>`

**GetAttributeNode**(uri As `String</api/data_types/string>`, name As `String</api/data_types/string>`) As `XMLAttribute</api/text/xml/xmlattribute>`

> Gets an XML attribute node of the attribute specified by *index* position. *index* is zero-based.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> This example shows how to walk over the team nodes in the above XML and displays each team name:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> Var an As XmlAttribute
> While n <> Nil
>   an = n.GetAttributeNode("name")
>   MessageBox(n.Name + ": " + an.Value)
>
>   n = n.NextSibling
> Wend
> ```

<div id="xmlnode.insert">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.Insert

**Insert**(newChild As XMLNode, beforeChild As XMLNode) As XMLNode

> Inserts *newChild* before the position of *beforeChild*. It optionally returns a reference to the inserted node as an <span class="title-ref">XMLNode</span>.
>
> The children being added must be children of the node/document to which they are being inserted. The example demonstrates this.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> To add a new team before the first team in the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> Var n1 As XmlNode = xml.DocumentElement.FirstChild
>
> ' Insert a new team before the first team currently
> ' in the XML
> Var newTeam As XmlNode
> newTeam = xml.DocumentElement.AppendChild(xml.CreateElement("Team"))
> newTeam.SetAttribute("name", "Eagles")
>
> xml.DocumentElement.Insert(newTeam, n1)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Eagles"/>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```

<div id="xmlnode.removeattribute">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.RemoveAttribute

**RemoveAttribute**(name As `String</api/data_types/string>`)

> Removes the *name* attribute.

<div id="xmlnode.removeattributenode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.RemoveAttributeNode

**RemoveAttributeNode**(attributeNode As `XMLAttribute</api/text/xml/xmlattribute>`) As `XMLAttribute</api/text/xml/xmlattribute>`

> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Remove the name attribute from the first Team:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.FirstChild
> Var an As XmlAttribute
> an = n.GetAttributeNode("name")
> n.RemoveAttributeNode(an)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team>
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```

<div id="xmlnode.removechild">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.RemoveChild

**RemoveChild**(oldChild As XMLNode)

> Removes *oldChild* from the XML.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Remove the "Seagulls" team from the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> Var n As XmlNode = xml.DocumentElement.FirstChild
> Call xml.DocumentElement.RemoveChild(n)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```

<div id="xmlnode.replacechild">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.ReplaceChild

**ReplaceChild**(newChild As XMLNode, oldChild As XMLNode) As XMLNode

> Replaces *oldChild* with *newChild*.
>
> ReplaceChild optionally returns a reference to the new child as an <span class="title-ref">XMLNode</span>.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Replaces the "Seagulls" with a new team "Eagles":
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> Var teamNode As XmlNode
> Var playerNode As XmlNode
>
> ' Create a new team
> teamNode = xml.DocumentElement.AppendChild(xml.CreateElement("Team"))
> teamNode.SetAttribute("name", "Eagles")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Fred")
> playerNode.SetAttribute("position", "1B")
>
> playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
> playerNode.SetAttribute("name", "Phil")
> playerNode.SetAttribute("position", "2B")
>
> ' Replace the "Seagulls" with the "Eagles"
> xml.DocumentElement.ReplaceChild(teamNode, n)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Eagles">
>     <Player name="Fred" position="1B"/>
>     <Player name="Phil" position="2B"/>
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B"/>
>     <Player name="Tim" position="2B"/>
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B"/>
>     <Player name="Ty" position="2B"/>
>   </Team>
> </League>
> ```

<div id="xmlnode.setattribute">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.SetAttribute

**SetAttribute**(name As `String</api/data_types/string>`, value As `String</api/data_types/string>`)

**SetAttribute**(uri As `String</api/data_types/string>`, name As `String</api/data_types/string>`, value As `String</api/data_types/string>`)

> This syntax sets an attribute and declares a namespace.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Add a "city" attribute to the first team:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
> Var n As XmlNode = xml.DocumentElement.FirstChild
> n.SetAttribute("city", "Boston")
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls" city="Boston">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```

<div id="xmlnode.setattributenode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.SetAttributeNode

**SetAttributeNode**(attributeNode As `XMLAttribute</api/text/xml/xmlattribute>`) As `XMLAttribute</api/text/xml/xmlattribute>`

**SetAttributeNode**(attributeNode As `XMLAttribute</api/text/xml/xmlattribute>`)

> Sets an attribute node.
>
> SetAttributeNode optionally returns a reference to a node as an XMLAttribute that had the same name and was replaced.
>
> The following XML is stored in a constant called `kXML`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```
>
> Adds a "city" attribute to the first team:
>
> ``` Xojo
> Var xml As New XmlDocument(kXML)
>
> Var n As XmlNode = xml.DocumentElement.FirstChild
>
> Var a As XmlAttribute
> a = xml.CreateAttribute("city")
> a.Value = "Boston"
>
> n.SetAttributeNode(a)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls" city="Boston">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Ben" position="1B" />
>     <Player name="Ty" position="2B" />
>   </Team>
> </League>
> ```

<div id="xmlnode.xql">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

XMLNode.XQL

**XQL**(query As `String</api/data_types/string>`) As `XMLNodeList</api/text/xml/xmlnodelist>`

**XQL**(query As `String</api/data_types/string>`, map() As `String</api/data_types/string>`) As `XMLNodeList</api/text/xml/xmlnodelist>`

> Performs an XPath 1.0 query and returns an `XMLNodeList</api/text/xml/xmlnodelist>` of the resulting nodes.
>
> If the *query* has namespace references in it, you must provide declarations for them in the form of a string array, such as:
>
> ``` Xojo
> Var map() As String = Array("ns1","http://foo","ns2","http://bar")
> ```
>
> Xql is also called XPath. Version 1.0 of XPath are supported.
>
> For more information about XPath:
>
> - <https://www.w3schools.com/xml/xpath_intro.asp>
> - <http://www.w3.org/TR/xpath/>
>
> The example code below uses this XML. Assign it to a constant called `kTestXml`:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>   </Team>
>   <Team name="Pigeons">
>     <Player name="Bill" position="1B" />
>     <Player name="Tim" position="2B" />
>   </Team>
>   <Team name="Crows">
>     <Player name="Who" position="1B" />
>     <Player name="What" position="2B" />
>     <Player name="I Don't Know" position="3B" />
>   </Team>
> </League>
> ```
>
> To get all the player names, you can use "//Player" as the query:
>
> ``` Xojo
> ' Load XML
> Var xml As New XmlDocument
> Try
>   xml.LoadXml(kTestXml)
> Catch e As XmlException
>   MessageBox("XML error: " + e.Message)
> End Try
>
> ' Display all the Player names
> Var nodes As XmlNodeList
> nodes = xml.XQL("//Player") ' Find all Player nodes in XML
>
> ' Loop through results and display each name attribute
> Var node As XmlNode
> For i As Integer = 0 To nodes.Length - 1
>   node = nodes.Item(i)
>   MessageBox("Player: " + node.GetAttribute("name"))
> Next
> ```

## Notes

Note that not every property is utilized on every node type. For example, the Value property is used on an `XMLAttribute</api/text/xml/xmlattribute>` and `XMLTextNode</api/text/xml/xmltextnode>`, but not an `XMLElement</api/text/xml/xmlelement>`.

## Sample code

The following XML:

``` XML
<?xml version="1.0" encoding="UTF-8"?>
<League>
  <Team name="Seagulls">
      <Player name="Bob" position="1B" />
      <Player name="Tom" position="2B" />
  </Team>
  <Team name="Pigeons">
      <Player name="Bill" position="1B" />
      <Player name="Tim" position="2B" />
  </Team>
  <Team name="Crows">
      <Player name="Ben" position="1B" />
      <Player name="Ty" position="2B" />
  </Team>
</League>
```

Can be created using this code, which displays the XML to a TextArea and prompts you to save it to a file:

``` Xojo
Var xml As New XmlDocument

Var root As XmlNode
root = xml.AppendChild(xml.CreateElement("League"))

Var teamNode As XmlNode
Var playerNode As XmlNode

' Create 1st team and its players
teamNode = root.AppendChild(xml.CreateElement("Team"))
teamNode.SetAttribute("name", "Seagulls")

playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
playerNode.SetAttribute("name", "Bob")
playerNode.SetAttribute("position", "1B")

playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
playerNode.SetAttribute("name", "Tom")
playerNode.SetAttribute("position", "2B")

' Create 2nd team and its players
teamNode = root.AppendChild(xml.CreateElement("Team"))
teamNode.SetAttribute("name", "Pigeons")

playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
playerNode.SetAttribute("name", "Bill")
playerNode.SetAttribute("position", "1B")

playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
playerNode.SetAttribute("name", "Tim")
playerNode.SetAttribute("position", "2B")

' Create 3rd team and its players
teamNode = root.AppendChild(xml.CreateElement("Team"))
teamNode.SetAttribute("name", "Crows")

playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
playerNode.SetAttribute("name", "Ben")
playerNode.SetAttribute("position", "1B")

playerNode = teamNode.AppendChild(xml.CreateElement("Player"))
playerNode.SetAttribute("name", "Ty")
playerNode.SetAttribute("position", "2B")

TextArea1.Text = xml.ToString

DisplayXML(xml)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code iterates through the XML created above and displays it in a ListBox:

``` Xojo
Sub DisplayXML(xml As XmlDocument)
  Var root As XmlNode
  root = xml.DocumentElement

  XMLList.DeleteAllRows

  Var teamNode As XmlNode
  Var playerNode As XmlNode
  For team As Integer = 0 To root.ChildCount-1

    ' Add Team name
    teamNode = root.Child(team)
    XMLList.AddRow(teamNode.GetAttribute("name"))

    ' Add Players
    For player As Integer = 0 To teamNode.ChildCount-1
      playerNode = teamNode.Child(player)
      XMLList.AddRow(playerNode.GetAttribute("name"), _
      playerNode.GetAttribute("position"))
    Next

  Next
End Sub
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `XMLDocument</api/text/xml/xmldocument>`, `XMLElement</api/text/xml/xmlelement>`, `XMLNodeList</api/text/xml/xmlnodelist>` classes.

</div>
