> 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/xmlvalidate.md).

# XMLValidate

Uses a Document Type Definition (DTD) or XML Schema to validate an XML text document or an XML document object.

Returns keys status (boolean), errors (array), fatalerrors (array) and warnings (array)

## Method Signature

```
XMLValidate(XML=[any], validator=[string])
```

### Arguments

| Argument    | Type     | Required | Description                                                                                                        | Default |
| ----------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------ | ------- |
| `XML`       | `any`    | `true`   | The XML text document or XML document object to validate.                                                          |         |
| `validator` | `string` | `false`  | The DTD or XML Schema to use for validation. If not provided, the DTD declaration within the XML document is used. |         |

## Examples

### Validate against an XML Schema

Validates that note.xml is valid according to the schema note.xsd.

[Run Example](https://try.boxlang.io/?code=eJyryM0JS8zJTEksSdVQUMooKSkottLXLy8v1ys3Lk7OyM%2FPKdZLzs%2FVr8jN0c%2FLL0nVAzKUdIhTWZyipKCpFxziGBIabM0FAPhjJN4%3D)

```java
xmlValidate( "https://www.w3schools.com/xml/note.xml", "https://www.w3schools.com/xml/note.xsd" ).STATUS;

```

Result: false

### Additional Examples

```java
validator = "
		<?xml version=""1.0""?>
		<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
			<xs:element name=""note"">
				<xs:complexType>
					<xs:sequence>
						<xs:element name=""to"" type=""xs:string""/>
						<xs:element name=""from"" type=""xs:string""/>
						<xs:element name=""heading"" type=""xs:string""/>
						<xs:element name=""body"" type=""xs:string""/>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:schema>
		";
xml_stream = "
			<?xml version=""1.0"" encoding=""UTF-8""?>
			<note>
				<to>Alice</to>
				<from>Bob</from>
				<heading>Reminder</heading>
				<body>Here is the message you requested.</body>
			</note>";
xml_document = XmlParse( xml_stream );
dump( xmlValidate( xml_document, validator ) );

```

## Related

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


---

# 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/xmlvalidate.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.
