# XMLFormat

Formats a string so that special XML characters can be used as text in XML

## Method Signature

```
XMLFormat(string=[string], escapeChars=[boolean])
```

### Arguments

| Argument      | Type      | Required | Description                                                                                                                                                            | Default |
| ------------- | --------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `string`      | `string`  | `true`   | The string to format                                                                                                                                                   |         |
| `escapeChars` | `boolean` | `false`  | <p>whether to escape additional characters restricted as per XML standards. For details, see<br><http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-RestrictedChar>.</p> | `false` |

## Examples

### Basic xmlFormat() usage

In this example we demonstrate passing the invalid characters < and & into the xmlFormat() function to make them XML safe.

[Run Example](https://try.boxlang.io/?code=eJwrL8osSfUvLSkoLdFQqMjNccsvyk0EMpVs8vJTUu3c8%2FNTFNQScwusFbxKM5MrbfTBwkoKmgqa1lwAp5cT%2FQ%3D%3D)

```java
writeOutput( xmlFormat( "<node>Good &amp; Juicy</node>" ) );

```

Result: \<node>Good \&amp; Juicy\</node>

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJwrLinKzEtXsFVQ8lTIycxOVShITcwrLVFIKi0pSS1SUFPISs3JqdRTsuZKKc0t0FCIyM1xyy%2FKTSzRUCiGaNVU0LTmUtDXV8BuQGJugTXUEC4AsI0jVw%3D%3D)

```java
string = "I like peanut butter & jelly.";
dump( XmlFormat( string ) );
 // I like peanut butter &amp; jelly.

```

## Related

* [XMLChildPos](/boxlang-language/reference/built-in-functions/xml/xmlchildpos.md)
* [XMLElemNew](/boxlang-language/reference/built-in-functions/xml/xmlelemnew.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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
