XMLDocument.LoadXML

From Xojo Documentation

Method

XMLDocument.LoadXML(doc As String)

Supported for all project types and targets.

Parses the passed XML string into the document.


Method

XMLDocument.LoadXML(file As FolderItem)

Supported for all project types and targets.

Parses the passed XML file into the document.

Notes

Always check for an XMLException when loading XML from strings or files.

Examples

This example loads the following XML, contained in a constant called kTestXml, into a new XMLDocument:

 <?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>
// Load XML
Var xml As New XmlDocument
Try
xml.LoadXml(kTestXml)
Catch e As XmlException
MessageBox("XML error: " + e.Message)
End Try

This example prompts the user to choose an XML file to load:

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