InsertElement method: XmlNode class

Syntax

InsertElement(TagName, Position)

Description

Use the InsertElement method to insert an element in an XmlNode at the location specified by Position.

Parameters

Parameter Description

TagName

Specify the tagname for the element as a string.

Position

Specify where you want to insert the element, as a number.

Returns

A reference to the newly created element.

Example

For example:

Local XmlDoc &inXMLDoc;
Local XmlNode &dataNode;
Local XmlNode &elementNode;

&inXMLDoc = CreateXmlDoc("<?xml version='1.0'?><root/>");
&dataNode = &inXMLDoc.DocumentElement.AddElement("data");
&elementNode = &dataNode.AddElement("first");
&elementNode = &dataNode.AddElement("second");

&commentNode = &dataNode.InsertElement("third", 2);

This is the XML document before the insert:

<?xml version="1.0"?>
<root>
  <data>
    <first/>
    <second/>
  </data>
</root>

This is the XML document after the insert:

<?xml version="1.0"?>
<root>
  <data>
    <first/>
    <third/>
    <second/>
  </data>
</root>