# 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](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlchildpos)
* [XMLElemNew](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlelemnew)
* [XMLGetNodeType](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlgetnodetype)
* [XMLNew](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlnew)
* [XMLParse](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlparse)
* [XMLSearch](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlsearch)
* [XMLTransform](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmltransform)
* [XMLValidate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/xml/xmlvalidate)
