TXTextControl.XmlElement.AddChild Method

Adds a new XML element as a sub-element of this element. The new element is placed at the position specified through the document's DTD.

AddChild(XmlElement)

Adds the specified XML element as a sub-element of this element. The new element is placed at the position specified through the document's DTD.

[C#]
public bool AddChild(XmlElement element);
[Visual Basic]
Public Function AddChild(ByVal element As XmlElement) As Boolean
Parameter Description
element

Specifies the XML element to add.

AddChild(XmlElement, Int32, Int32)

Adds the specified XML element as a sub-element of this element. The new element is placed at the position specified through the document's DTD. If this element can have more than one child of the specified type, the before or after parameters can be used to specify a position.

[C#]
public bool AddChild(XmlElement element, int before, int after);
[Visual Basic]
Public Function AddChild(ByVal element As XmlElement, ByVal before As Integer, ByVal after As Integer) As Boolean
Parameter Description
element

Specifies the XML element to add.

before

Specifies a relative position in the list of child elements of the specified type beginning with 1. The XML element to be added is placed before the child identified by the before parameter. You can specify before or after positions but not both. If this parameter is -1, it is ignored.

after

Specifies a relative position in the list of child elements of the specified type beginning with 1. The XML element to be added is placed after the child identified by the after parameter. You can specify before or after positions but not both. If this parameter is -1, it is ignored.

Return Value

The return is false, if the new element could not be added because the document becomes invalid according to the document's DTD. In this case an XmlInvalid event occurs. The return value is true, if the new element could successfully been added.

Example

The following example creates a new Telephone element and adds it to the second address in an XML document that contains adresses consisting of the sub-elements Name, Street, City and Telephone:

[C#]
TXTextControl.XmlElement newElement = new TXTextControl.XmlElement("Telephone", "046798 / 3459786");
textControl1.GetXmlElements("Adress").GetItem(2).AddChild(newElement);
[Visual Basic]
Dim NewElement As New TXTextControl.XmlElement("Telephone", "046798 / 3459786")
TextControl1.GetXmlElements("Adress").GetItem(2).AddChild(NewElement)

See Also