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

# XMLSearch

Get XML values according to given xPath query

## Method Signature

```
XMLSearch(XMLNode=[XML], xpath=[String], params=[Struct])
```

### Arguments

| Argument  | Type     | Required | Description                               | Default |
| --------- | -------- | -------- | ----------------------------------------- | ------- |
| `XMLNode` | `XML`    | `true`   | The XML node to search                    |         |
| `xpath`   | `String` | `true`   | The xpath query to search for             |         |
| `params`  | `Struct` | `false`  | The parameters to pass to the xpath query | `{}`    |

## Examples

### Read specific properties from XML collection

XPath extracts 'name' property from every user given in the XML collection

```java
<bx:savecontent variable="xmlstring">
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <users>
        <user id="1">
            <name>Me</name>
        </user>
        <user id="2">
            <name>You</name>
            <address>
                <street>Long Road</street>
            </address>
        </user>
    </users>
</bx:savecontent>
<bx:script>
	xml = XMLParse( xmlstring );
	result = xmlSearch( xml, "users//name" );
	userlist = "";
	for( i = 1; i <= ArrayLen( result ); i++ ) {
		userlist = ListAppend( userlist, result[ i ].XMLTEXT );
	}
	writeOutput( userlist );
</bx:script>

```

Result: Me,You

### Additional Examples

```java
xml_stream = "
			<?xml version=""1.0"" encoding=""UTF-8""?>
			<notes>
				<note>
					<to>Alice</to>
					<from>Bob</from>
					<heading>Reminder</heading>
					<body>Here is the message you requested.</body>
				</note>
				<note>
					<to>Bob</to>
					<from>Alice</from>
					<heading>Your request</heading>
					<body>I got your message; all is well.</body>
				</note>
			</notes>";
xml_document = XmlParse( xml_stream );
dump( XmlSearch( xml_document, "/notes/note[last()]/body" ) );
 // I got your message; all is well.

```

## 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)
* [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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
