# XmlParse()

Converts an XML document that is represented as a string variable into an XML document object.

```
XmlParse( xmlString=string, caseSensitive=boolean, validator=any, lenient=boolean );
```

**Returns:** xml

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| xmlString | string | Yes | Any of the following: *Alias: xmlStr, xmlText, xml* |  |
| caseSensitive | boolean | No | Maintains the case of document elements and attributes. Default: false |  |
| validator | any | No | Any of the following: - A string containing a DTD or Schema - The name of a DTD or Schema file - The URL of a DTD or Schema file; valid protocol identifiers include http, https, ftp, and file - A struct of `xmlFeatures` directives (since 5.4.2.20) — overrides the application-level XML security settings for this single parse call. See the usage notes below for available keys. |  |
| lenient | boolean | No | if set to true, the parser is more lenient and forgives invalid XML and does the best to interpret it. | false |

# Usage Notes

Since Lucee 5.4.2 and 6.0, XML parsing is secure by default — DOCTYPE declarations and external entities are blocked to prevent XXE attacks.

You can pass a struct of `xmlFeatures` as the `validator` argument to override the security settings for a single parse call, or set `this.xmlFeatures` in `Application.cfc` for application-wide configuration.

See the [XML Security with xmlFeatures](../../recipes/xml-security-xmlfeatures.md) recipe for full details and examples.

# Examples

**Basic Usage**

```1
xml_stream = "
	<note>
		<to>Alice</to>
		<from>Bob</from>
		<heading>Reminder</heading>
		<body>Here is the message you requested.</body>
	</note>
";

dump( XmlParse( xml_stream ) );
```

**Parsing XML with DOCTYPE (xmlFeatures override)**

By default, XML containing a DOCTYPE declaration is blocked. To parse such XML, pass an `xmlFeatures` struct as the `validator` argument:

```1
xmlWithDoctype = '<?xml version="1.0"?>
	<!DOCTYPE hibernate-mapping PUBLIC
		"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
		"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
	<hibernate-mapping></hibernate-mapping>';

// this will throw an error with secure defaults
try {
	doc = xmlParse( xmlWithDoctype );
	echo( "parsed ok" );
} catch ( e ) {
	echo( "Blocked: " & e.message );
}

echo( "<br><br>" );

// override xmlFeatures to allow DOCTYPE for this call only
doc = xmlParse( xmlWithDoctype, false, {
	"secure": false,
	"disallowDoctypeDecl": false,
	"externalGeneralEntities": false
} );
echo( "Parsed with override: " & doc.xmlRoot.xmlName );
```

See the [XML Security with xmlFeatures](/docs/recipes/xml-security-xmlfeatures) recipe for more details.




## Related System Properties / Environment Variables

- [LUCEE_XMLFEATURES_OVERRIDE_DISABLE](../environment-variables-system-properties.md#lucee_xmlfeatures_override_disable) - Boolean value to disable overriding XML parser features for security reasons
  ***Type:** boolean, **Default:** false*



# Categories

[Parsing](../../categories/parsing.md), [XML](../../categories/xml.md)

# See Also

[HtmlParse()](htmlparse.md), [Read XML with a listener Model (SAX)](../../recipes/read-xml-with-a-listener-model-sax.md), [XML Fast And Easy, using SAX - Listener Functions](../../recipes/xml-fast-and-easy.md), [XML Security with xmlFeatures](../../recipes/xml-security-xmlfeatures.md)