Class

# XMLDocument

<div class="rst-class">

forsearch

</div>

XmlDocument

<div class="rst-class">

forsearch

</div>

Xml

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

## Description

Use to represent a XML document.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

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

## Methods

<div class="rst-class">

table-centered_column_4

</div>

<table>
<thead>
<tr class="header">
<th>Name</th>
<th>Parameters</th>
<th>Returns</th>
<th>Shared</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code class="interpreted-text" role="ref">AppendChild&lt;xmldocument.appendchild&gt;</code></td>
<td>newChild As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">Child&lt;xmldocument.child&gt;</code></td>
<td>index As <code class="interpreted-text" role="doc">Integer&lt;/api/data_types/integer&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">Clone&lt;xmldocument.clone&gt;</code></td>
<td>deep As <code class="interpreted-text" role="doc">Boolean&lt;/api/data_types/boolean&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">Compare&lt;xmldocument.compare&gt;</code></td>
<td>node As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td><code class="interpreted-text" role="doc">Integer&lt;/api/data_types/integer&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">Constructor&lt;xmldocument.constructor0&gt;</code></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">Constructor&lt;xmldocument.constructor1&gt;</code></td>
<td>xmlDoc As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">Constructor&lt;xmldocument.constructor2&gt;</code></td>
<td>fItem As <code class="interpreted-text" role="doc">FolderItem&lt;/api/files/folderitem&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">CreateAttribute&lt;xmldocument.createattribute&gt;</code></td>
<td>qName As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td>uri As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, qName As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">CreateCDATASection&lt;xmldocument.createcdatasection&gt;</code></td>
<td>data As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLCDATASection&lt;/api/text/xml/xmlcdatasection&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">CreateComment&lt;xmldocument.createcomment&gt;</code></td>
<td>data As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLComment&lt;/api/text/xml/xmlcomment&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">CreateElement&lt;xmldocument.createelement&gt;</code></td>
<td>tagName As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLElement&lt;/api/text/xml/xmlelement&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td>uri As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, tagname As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLElement&lt;/api/text/xml/xmlelement&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">CreateProcessingInstruction&lt;xmldocument.createprocessinginstruction&gt;</code></td>
<td>target As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, data As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLProcessingInstruction&lt;/api/text/xml/xmlprocessinginstruction&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">CreateTextNode&lt;xmldocument.createtextnode&gt;</code></td>
<td>data As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLTextNode&lt;/api/text/xml/xmltextnode&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">GetAttribute&lt;xmldocument.getattribute&gt;</code></td>
<td>name As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td>uri As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, name As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">GetAttributeNode&lt;xmldocument.getattributenode&gt;</code></td>
<td>Name As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">ImportNode&lt;xmldocument.importnode&gt;</code></td>
<td>foreignNode As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code>, deep As <code class="interpreted-text" role="doc">Boolean&lt;/api/data_types/boolean&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">Insert&lt;xmldocument.insert&gt;</code></td>
<td>newChild As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code>, beforeChild As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">LoadXML&lt;xmldocument.loadxml&gt;</code></td>
<td>doc As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td></td>
<td>fItem As <code class="interpreted-text" role="doc">FolderItem&lt;/api/files/folderitem&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">RemoveAttribute&lt;xmldocument.removeattribute&gt;</code></td>
<td>name As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">RemoveAttributeNode&lt;xmldocument.removeattributenode&gt;</code></td>
<td>attributeNode As <code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">RemoveChild&lt;xmldocument.removechild&gt;</code></td>
<td>oldChild As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">ReplaceChild&lt;xmldocument.replacechild&gt;</code></td>
<td>newChild As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code>, oldChild As <code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNode&lt;/api/text/xml/xmlnode&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><code class="interpreted-text" role="ref">SaveXML&lt;xmldocument.savexml&gt;</code></td>
<td>fItem As <code class="interpreted-text" role="doc">FolderItem&lt;/api/files/folderitem&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">SetAttribute&lt;xmldocument.setattribute&gt;</code></td>
<td>name As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, value As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td>uri As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, name As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, value As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">SetAttributeNode&lt;xmldocument.setattributenode&gt;</code></td>
<td>attributeNode As <code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td>attributeNode As <code class="interpreted-text" role="doc">XMLAttribute&lt;/api/text/xml/xmlattribute&gt;</code></td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">Transform&lt;xmldocument.transform&gt;</code></td>
<td>xsl As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td></td>
<td>xsl As <code class="interpreted-text" role="doc">XMLStyleSheet&lt;/api/text/xml/xmlstylesheet&gt;</code>, saxHandler As <code class="interpreted-text" role="doc">XMLXsltHandler&lt;/api/text/xml/xmlxslthandler&gt;</code></td>
<td><code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td></td>
</tr>
<tr class="even">
<td><code class="interpreted-text" role="ref">XQL&lt;xmldocument.xql&gt;</code></td>
<td>query As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNodeList&lt;/api/text/xml/xmlnodelist&gt;</code></td>
<td></td>
</tr>
<tr class="odd">
<td><blockquote>
<p>""</p>
</blockquote></td>
<td>query As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code>, map() As <code class="interpreted-text" role="doc">String&lt;/api/data_types/string&gt;</code></td>
<td><code class="interpreted-text" role="doc">XMLNodeList&lt;/api/text/xml/xmlnodelist&gt;</code></td>
<td></td>
</tr>
</tbody>
</table>

## Property descriptions

<div id="xmldocument.attributecount">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.AttributeCount

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

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

<div id="xmldocument.childcount">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.documentelement">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.DocumentElement

**DocumentElement** As `XMLElement</api/text/xml/xmlelement>`

> Refers to the top-level (root) element of the document.
>
> You will always start processing the XML document starting with the DocumentElement 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="xmldocument.encoding">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Encoding

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

> The Internet Text Encoding name, such as UTF-8.

<div id="xmldocument.firstchild">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.FirstChild

**FirstChild** As `XMLNode</api/text/xml/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="xmldocument.lastchild">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.LastChild

**LastChild** As `XMLNode</api/text/xml/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="xmldocument.lasterror">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.localname">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.name">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.namespaceuri">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.NamespaceURI

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

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

<div id="xmldocument.nextsibling">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.NextSibling

**NextSibling** As `XMLNode</api/text/xml/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="xmldocument.ownerdocument">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.OwnerDocument

**OwnerDocument** As **XMLDocument**

> The <span class="title-ref">XMLDocument</span> that contains this node.
>
> Use this property to get a reference to the <span class="title-ref">XMLDocument</span> 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 XMLNode, but no longer have a reference to the <span class="title-ref">XMLDocument</span> that contains it.
>
> This property is read-only.

<div id="xmldocument.parent">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Parent

**Parent** As `XMLNode</api/text/xml/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="xmldocument.prefix">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Prefix

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

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

<div id="xmldocument.preservewhitespace">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.PreserveWhitespace

**PreserveWhitespace** As `Boolean</api/data_types/boolean>`

> When `False</api/language/false>`, white space characters (spaces, carriage returns, tabs, etc.) are removed from within XML elements when the XML file is loaded. The default is `False</api/language/false>`.
>
> When `True</api/language/true>`, white space characters are retained. You can only change PreserveWhitespace to `True</api/language/true>` before calling `LoadXml<xmldocument.loadxml>`. It has no affect when set after the XML file has been loaded.
>
> As an example, the following XML section has a space within the \<trans\> node:
>
> ``` XML
> <trans loc="fr"> </trans>
> ```
>
> When PreserveWhitespace is `False</api/language/false>`, the XML gets loaded as:
>
> ``` XML
> <trans loc="fr"></trans>
> ```
>
> When PreserveWhitespace is `True</api/language/true>`, the space in the XML node is retained:
>
> ``` XML
> <trans loc="fr"> </trans>
> ```
>
> Note that this can cause you to have to look at additional nodes that might otherwise have been blank.

<div id="xmldocument.previoussibling">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.PreviousSibling

**PreviousSibling** As `XMLNode</api/text/xml/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="xmldocument.tostring">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.type">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.value">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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 XMLNode subclasses.
>
> </div>

## Method descriptions

<div id="xmldocument.appendchild">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.AppendChild

**AppendChild**(newChild As `XMLNode</api/text/xml/xmlnode>`) As `XMLNode</api/text/xml/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="xmldocument.child">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Child

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

> Returns the child XMLNode 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 <span class="title-ref">XMLDocument</span> 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="xmldocument.clone">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Clone

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

> Duplicates the current node. The *Deep* parameter indicates whether to also duplicate all the child nodes. It returns an XMLNode.
>
> 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="xmldocument.compare">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Compare

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

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

<div id="xmldocument.constructor0">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Constructor

**Constructor**

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates an empty <span class="title-ref">XMLDocument</span> instance.

<div id="xmldocument.constructor1">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Constructor

**Constructor**(xmlDoc As `String</api/data_types/string>`)

> Parses the passed XML string into the document.
>
> This example loads the following XML, contained in a constant called `kXml`, into a new \`XMLDocument\`:
>
> ``` 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(kXml)
> Catch e As XmlException
>   MessageBox("XML error: " + e.Message)
> End Try
> ```

<div id="xmldocument.constructor2">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Constructor

**Constructor**(fItem As `FolderItem</api/files/folderitem>`)

> Parses the passed XML file into the document.

<div id="xmldocument.createattribute">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateAttribute

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

> Creates an attribute node as an `XMLAttribute</api/text/xml/xmlattribute>`.

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

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateAttribute

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

> Creates an attribute node as an `XMLAttribute</api/text/xml/xmlattribute>` with a namespace declaration.
>
> After you create an attribute, you have to add it to the <span class="title-ref">XMLDocument</span> using SetAttributeNode.
>
> 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 an attribute to the first team node (Seagulls):
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> ' Create an attribute node and assign it a value
> Var xa As XmlAttribute
> xa = xml.CreateAttribute("TestAttribute")
> xa.Value = "Test"
>
> ' Add the attribute to the XML document
> xml.DocumentElement.FirstChild.SetAttributeNode(xa)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls" TestAttribute="Test">
>     <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="xmldocument.createcdatasection">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateCDATASection

**CreateCDATASection**(data As `String</api/data_types/string>`) As `XMLCDATASection</api/text/xml/xmlcdatasection>`

> Creates a CDATA section with the passed *data* and returns it as an `XMLCDATASection</api/text/xml/xmlcdatasection>`.
>
> 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 CDATA section to the first team in the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> ' Create a CDATA section node and assign it a value
> Var data As String =  "<h1>Hello!</h1>"
> Var xcdata As XmlCDATASection
> xcdata = xml.CreateCDATASection(data)
>
> ' Add the CDATA section to the XML document
> xml.DocumentElement.FirstChild.AppendChild(xcdata)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>     <![CDATA[<h1>Hello!</h1>]]>
>   </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="xmldocument.createcomment">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateComment

**CreateComment**(data As `String</api/data_types/string>`) As `XMLComment</api/text/xml/xmlcomment>`

> Creates an `XMLComment</api/text/xml/xmlcomment>` with the passed *data* and returns it as an `XMLComment</api/text/xml/xmlcomment>`.
>
> 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 comment to the first team node:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> ' Create a Comment and assign it a value
> Var xc As XmlComment
> xc = xml.CreateComment("TestComment")
> xc.Value = "This node contains team information."
>
> ' Add the Comment to the XML document
> xml.DocumentElement.FirstChild.AppendChild(xc)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>     <!--This node contains team information.-->
>   </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="xmldocument.createelement">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateElement

**CreateElement**(tagName As `String</api/data_types/string>`) As `XMLElement</api/text/xml/xmlelement>`

> Creates an element as an `XMLElement</api/text/xml/xmlelement>`. Returns an `XMLElement</api/text/xml/xmlelement>`.

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

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateElement

**CreateElement**(uri As `String</api/data_types/string>`, tagName As `String</api/data_types/string>`) As `XMLElement</api/text/xml/xmlelement>`

> Creates an element with a namespace declaration as an `XMLElement</api/text/xml/xmlelement>`. Returns an `XMLElement</api/text/xml/xmlelement>`.
>
> 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 to the XML:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> ' Add a new Team to the XML
> Var xe As XmlElement
> xe = xml.CreateElement("Team")
> xe.SetAttribute("name", "Eagles")
>
> ' Add the Comment to the XML document
> xml.DocumentElement.AppendChild(xe)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` 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>
>   <Team name="Eagles"/>
> </League>
> ```

<div id="xmldocument.createprocessinginstruction">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateProcessingInstruction

**CreateProcessingInstruction**(target As `String</api/data_types/string>`, data As `String</api/data_types/string>`) As `XMLProcessingInstruction</api/text/xml/xmlprocessinginstruction>`

> Creates an `XMLProcessingInstruction</api/text/xml/xmlprocessinginstruction>` with the passed *target* keyword and *data*.
>
> A [processing instruction](http://en.wikipedia.org/wiki/Processing_Instruction) is a node type intended to carry instructions to the application.
>
> 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 processing instruction:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> ' Add a new Processing Instruction to the XML
> Var xpi As XmlProcessingInstruction
> xpi = xml.CreateProcessingInstruction("Target", "Data")
>
> ' Add the Processing Instruction to the XML document
> xml.AppendChild(xpi)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` 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>
> <?Target Data?>
> ```

<div id="xmldocument.createtextnode">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.CreateTextNode

**CreateTextNode**(data As `String</api/data_types/string>`) As `XMLTextNode</api/text/xml/xmltextnode>`

> Creates a text node with *data* and returns it as an `XMLTextNode</api/text/xml/xmltextnode>`.
>
> 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 text node to the first team node:
>
> ``` Xojo
> Var xml As New XmlDocument(kXml)
>
> ' Create a Text node and assign it a value
> Var xt As XmlTextNode
> xt = xml.CreateTextNode("Maine")
>
> ' Add the Text node to the XML document
> xml.DocumentElement.FirstChild.AppendChild(xt)
>
> TextArea1.Text = xml.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B" />
>     <Player name="Tom" position="2B" />
>     Maine
>   </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="xmldocument.getattribute">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.GetAttribute

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

> Gets the value of the attribute specified by *Name*.
>
> Returns "" (empty string) if the attribute does not exist.

**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*.
>
> 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="xmldocument.getattributenode">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.GetAttributeNode

**GetAttributeNode**(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="xmldocument.importnode">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.ImportNode

**ImportNode**(foreignNode As `XMLNode</api/text/xml/xmlnode>`, deep As `Boolean</api/data_types/boolean>`) As `XMLNode</api/text/xml/xmlnode>`

> Copies a node from another <span class="title-ref">XMLDocument</span> into the current document.
>
> If the parameter *deep* is `True</api/language/true>`, ImportNode will import all the child nodes of *foreignNode*. After you import a node, you must then place it somewhere within the <span class="title-ref">XMLDocument</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>
> ```
>
> To copy the first team into a new XML document:
>
> ``` Xojo
> Var xml1 As New XmlDocument(kXml)
> Var xml2 As New XmlDocument
>
> Var root As XmlNode
> root = xml2.AppendChild(xml2.CreateElement("League"))
>
> Var importNode As XmlNode
> importNode = xml2.ImportNode(xml1.DocumentElement.FirstChild, True)
>
> root.AppendChild(importNode)
>
> TextArea1.Text = xml2.ToString
> ```
>
> The result would then be:
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <League>
>   <Team name="Seagulls">
>     <Player name="Bob" position="1B"/>
>     <Player name="Tom" position="2B"/>
>   </Team>
> </League>
> ```

<div id="xmldocument.insert">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Insert

**Insert**(newChild As `XMLNode</api/text/xml/xmlnode>`, before As `XMLNode</api/text/xml/xmlnode>`) As `XMLNode</api/text/xml/xmlnode>`

> Inserts *newChild* before the position of *beforeChild*. It optionally returns a reference to the inserted node as an XMLNode.
>
> 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="xmldocument.loadxml">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.LoadXML

**LoadXML**(doc As `String</api/data_types/string>`)

> Parses the passed XML string into the document.
>
> This example loads the following XML, contained in a constant called `kXml`, into a new \`XMLDocument\`:
>
> ``` 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(kXml)
> Catch e As XmlException
>   MessageBox("XML error: " + e.Message)
> End Try
> ```

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

<div class="rst-class">

forsearch

</div>

XMLDocument.LoadXML

**LoadXML**(fItem As `FolderItem</api/files/folderitem>`)

> Parses the passed XML file into the document.
>
> Always check for an `XMLException</api/exceptions/xmlexception>` when loading XML from strings or files.
>
> This example prompts the user to choose an XML file to load:
>
> ``` Xojo
> Var xmlFile As FolderItem
> xmlFile = FolderItem.ShowOpenFileDialog("")
>
> If xmlFile <> Nil Then
>   Var xml As New XmlDocument
>
>   Try
>     xml.LoadXml(xmlFile)
>   Catch e As XmlException
>     MessageBox("XML error: " + e.Message)
>   End Try
> End If
> ```

<div id="xmldocument.removeattribute">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.RemoveAttribute

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

> Removes the *name* attribute.

<div id="xmldocument.removeattributenode">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.removechild">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.RemoveChild

**RemoveChild**(oldChild As `XMLNode</api/text/xml/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="xmldocument.replacechild">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.ReplaceChild

**ReplaceChild**(newChild As `XMLNode</api/text/xml/xmlnode>`, oldChild As `XMLNode</api/text/xml/xmlnode>`) As `XMLNode</api/text/xml/xmlnode>`

> Replaces *oldChild* with *newChild*.
>
> ReplaceChild optionally returns a reference to the new child as an XMLNode.
>
> 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="xmldocument.savexml">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.SaveXML

**SaveXML**(fItem As `FolderItem</api/files/folderitem>`)

> Saves the XML to the passed `FolderItem</api/files/folderitem>`.
>
> The following XML, stored in a constant called `kXML`, is saved to a file selected by the user:
>
> ``` 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
> Var saveFile As FolderItem
> saveFile = FolderItem.ShowSaveFileDialog("", "Test.xml")
>
> If saveFile <> Nil Then
>   Var xml As New XmlDocument
>   Try
>     xml.LoadXml(kXml)
>     xml.SaveXml(saveFile)
>   Catch fileError As IOException
>     MessageBox("Save error: " + FileError.Message)
>   Catch XMLError As XmlException
>     MessageBox("XML error: " + XMLError.Message)
>   End Try
> End If
> ```

<div id="xmldocument.setattribute">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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="xmldocument.setattributenode">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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 optional parameter *ns* determines whether to use and declare any namespace data found in the passed `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>
> ```
>
> 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="xmldocument.transform">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.Transform

**Transform**(xsl As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Creates a new XML document that is the result of applying an XSLT stylesheet string.

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

<div class="rst-class">

forsearch

</div>

XMLDocument.Transform

**Transform**(xsl As `XMLStyleSheet</api/text/xml/xmlstylesheet>`, saxHandler As `XMLXsltHandler</api/text/xml/xmlxslthandler>`) As `String</api/data_types/string>`

> Creates a new XML document that is the result of applying an XSLT stylesheet and register an event handler *saxHandler* to receive SAX style events on the output XML during the transformation.
>
> Versions 1.0 of XSLT and XPath are supported. XSLT is described at: <https://www.w3.org/TR/xslt/all/> and XPath at <https://www.w3.org/TR/xpath/all/>.
>
> You can use <span class="title-ref">XMLDocument</span>.Transform to generate pretty-printed XML data using the following XSL.
>
> ``` XML
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:output method="xml" indent="yes" />
>   <xsl:template match="/">
>     <xsl:copy-of select="/" />
>   </xsl:template>
> </xsl:transform>
> ```
>
> Save it in a project as a constant named `kPrettyPrintXSL`. Then the following code generates pretty-printed XML data from an <span class="title-ref">XMLDocument</span> object.
>
> ``` Xojo
> Var prettyXML As String = xml.Transform(kPrettyPrintXSL)
> ```

<div id="xmldocument.xql">

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

</div>

<div class="rst-class">

forsearch

</div>

XMLDocument.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 `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="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(kXml)
> 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

An <span class="title-ref">XMLDocument</span> is an internal data structure that can be converted to a string using the ToString function. An <span class="title-ref">XMLDocument</span> is used for both parsing existing XML data into a DOM document structure or creating a new XML document from scratch.

## 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.RemoveAllRows

  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">

`XMLNode</api/text/xml/xmlnode>` parent class; `XMLAttribute</api/text/xml/xmlattribute>`, `XMLComment</api/text/xml/xmlcomment>`, `XMLCDATASection</api/text/xml/xmlcdatasection>`, `XMLDOMException</api/exceptions/xmldomexception>`, `XMLElement</api/text/xml/xmlelement>`, `XMLException</api/exceptions/xmlexception>`, `XMLNode</api/text/xml/xmlnode>`, `XMLNodeList</api/text/xml/xmlnodelist>`, `XMLProcessingInstruction</api/text/xml/xmlprocessinginstruction>`, `XMLTextNode</api/text/xml/xmltextnode>` classes.

</div>
