TX Text Control .NET for WPF

RemoveChild Method

Method
Namespace
TXTextControl
Package
TXTextControl.TextControl.WPF.SDK as TXTextControl.dll from the private NuGet feed or Text Control Offline Packages

Description

Removes an XML child element.

Syntax

RemoveChild(string)

Removes the first XML child element with the specified name.

public bool RemoveChild(string name);
ParameterDescription
name

Specifies the name of the sub-element to remove.

RemoveChild(string, int)

Removes the XML child element with the specified name and index.

public bool RemoveChild(string name, int index);
ParameterDescription
name

Specifies the name of the sub-element to remove.

index

Specifies the number of the sub-element beginning with 1. If this value does not match any existing sub-element, an error occurs.

Return Value

The return value is false, if the element could not be removed 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 sub-element could successfully be removed.

Examples

The following example removes the second Telephone element of the second address in an XML document that contains adresses consisting of the sub-elements Name, Street, City and Telephone:

textControl1.GetXmlElements("Adress").GetItem(2).RemoveChild("Telephone", 2);

The following example removes a child XML element.

if (xmlElement.RemoveChild("CustomerName", 1))
{
    Console.WriteLine("Remove Child completed successfully.");
}