XMLDocument.CreateAttribute

From Xojo Documentation

Method

XMLDocument.CreateAttribute(Name as String) As XMLAttribute

Supported for all project types and targets.

Creates an attribute node as an XMLAttribute.


Method

XMLDocument.CreateAttribute(URI as String, Name as String) As XMLAttribute

Supported for all project types and targets.

Creates an attribute node as an XMLAttribute with a namespace declaration.

Notes

After you create an attribute, you have to add it to the XMLDocument using SetAttributeNode.

Example

The following XML is stored in a constant called kXML:

 <?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):

Dim xml As New XmlDocument(kXml)

// Create an attribute node and assign it a value
Dim 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