# RemoveChild Method

> Removes a sub-element by name and optional Index from an XMLElement; returns 0 on error, 1 if the DTD makes the document invalid, 2 on success.

- **Product:** TX Text Control ActiveX
- **Section:** Documentation
- **Kind:** Method
- **Path:** TX Text Control ActiveX > API Reference > XMLElement > RemoveChild Method
- **375 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-activex/reference/xmlelement/removechild-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-activex/reference/xmlelement/removechild-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-activex/reference/xmlelement/removechild-method/llms-full.txt

---

Removes a sub-element from this element. If this element has more than one sub-element of the type with the given name, the optional Index parameter can be used to specify the sub-element to remove. If Index is omitted Text Control removes the first sub-element with the given name.

### Syntax

```vbscript
XMLElement.RemoveChild ElementName[, Index]
```

### Parameters

| Parameter | Description |
|---|---|
| ElementName | Specifies the name of the sub-element to remove. |
| Index | Optional. Specifies the number of the subelement. If this value does not match any existing sub-element, an error occurs. |

### Return Value

The method returns one of the following values:

| Value | Description |
|---|---|
| 0 | An error has occurred. |
| 1 | The element could not be removed because the document becomes invalid according to the document's DTD. In this case Text Control fires an [XMLInvalid](https://docs.textcontrol.com/tx-text-control-activex/reference/txtextcontrol/xmlinvalid-event/llms-full.txt) event. |
| 2 | The sub-element has successfully been removed. |

### Examples

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

```vbscript
TXTextControl1.XMLElements("Address")(2).RemoveChild "Telephone", 2
```

### See Also

- [Working with XML Files](https://docs.textcontrol.com/tx-text-control-activex/document-editor/xml/llms-full.txt)
- [Programming Category: XML Programming](https://docs.textcontrol.com/tx-text-control-activex/reference/categories/xml/llms-full.txt)

---

## Nearby

- **Previous:** [ElementName Property](https://docs.textcontrol.com/tx-text-control-activex/reference/xmlelement/elementname-property/llms-full.txt)
- **Next:** [Select Method](https://docs.textcontrol.com/tx-text-control-activex/reference/xmlelement/select-method/llms-full.txt)
