AddChild Method
- Namespace
TXTextControl
- Package
TXTextControl.asTextControl. WinForms. SDK TXTextControl.from the private NuGet feed or Text Control Offline Packagesdll
Description
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.
Syntax
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.
public bool AddChild(XmlElement element);Public Function AddChild(element As XmlElement) As Boolean| Parameter | Description |
|---|---|
| element | Specifies the XML element to add. |
AddChild(XmlElement, int, int)
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.
public bool AddChild(XmlElement element, int before, int after);Public Function AddChild(element As XmlElement, before As Integer, 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.
Examples
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:
TXTextControl.XmlElement newElement = new TXTextControl.XmlElement("Telephone", "046798 / 3459786");
textControl1.GetXmlElements("Adress").GetItem(2).AddChild(newElement);Dim NewElement As New TXTextControl.XmlElement("Telephone", "046798 / 3459786")
TextControl1.GetXmlElements("Adress").GetItem(2).AddChild(NewElement)The following example adds a child XML element.
if (xmlElement.AddChild(new XmlElement("CustomerName")))
{
Console.WriteLine("Add Child completed successfully.");
}If xmlElement.AddChild(New XmlElement("CustomerName")) Then
Console.WriteLine("Add Child completed successfully.")
End If