> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlelemnew.md).

# XMLElemNew

Creates a new XML Element which can be appended to an XML document

## Method Signature

```
XMLElemNew(XML=[xml], childname=[string], namespace=[string])
```

### Arguments

| Argument    | Type     | Required | Description                                        | Default |
| ----------- | -------- | -------- | -------------------------------------------------- | ------- |
| `XML`       | `xml`    | `true`   | The parent XML object to associate the new node to |         |
| `childname` | `string` | `true`   | The XML name of the new child node                 |         |
| `namespace` | `string` | `false`  | The XML namespace to attach to the new child node  |         |

## Examples

### Simple xmlelemnew Example

Here, we've created myXml with root and child nodes using xmlelemnew().

```java
<bx:set myXml = xmlNew() >
<bx:set myXml.XMLROOT = xmlelemnew( myXml, "sampleXml" ) >
<bx:set myXml.SAMPLEXML.XMLTEXT = "This is Root node text" >
<bx:loop from="1" to="3" index="i">
	<bx:set myXml.SAMPLEXML.XMLCHILDREN[ i ] = xmlelemnew( myXml, "childNode#i#" ) >
	<bx:set myXml.SAMPLEXML.XMLCHILDREN[ i ].XMLTEXT = "This is Child node#i# text" >
</bx:loop>
<bx:dump var="#myXml#">
```

### Additional Examples

```java
xml_document = XmlNew(); // new XML document to populate
xml_root = XmlElemNew( xml_document, "notes" );
xml_document.XMLROOT = xml_root; // set the root node of the XML document
xml_child = XmlElemNew( xml_document, "note" ); // first child node
xml_secondary_child = XmlElemNew( xml_document, "to" ); // child node for the first child node
xml_child.XMLCHILDREN.append( xml_secondary_child );
xml_root.XMLCHILDREN.append( xml_child ); // add the first child node to the XML document
dump( xml_document );

```

## Related

* [XMLChildPos](/boxlang-language/reference/built-in-functions/xml/xmlchildpos.md)
* [XMLFormat](/boxlang-language/reference/built-in-functions/xml/xmlformat.md)
* [XMLGetNodeType](/boxlang-language/reference/built-in-functions/xml/xmlgetnodetype.md)
* [XMLNew](/boxlang-language/reference/built-in-functions/xml/xmlnew.md)
* [XMLParse](/boxlang-language/reference/built-in-functions/xml/xmlparse.md)
* [XMLSearch](/boxlang-language/reference/built-in-functions/xml/xmlsearch.md)
* [XMLTransform](/boxlang-language/reference/built-in-functions/xml/xmltransform.md)
* [XMLValidate](/boxlang-language/reference/built-in-functions/xml/xmlvalidate.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlelemnew.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
