# XmlReader

(plugins.XmlReader)

## Overview

`XMLReader` is an XML parsing tool designed to process XML data. It provides two main methods for reading XML content, catering to both file-based and string-based sources. Both methods provide access to the hierarchical structure of the XML, including child nodes, attributes, and content, making them versatile for various XML processing needs.

## **Returned Types**

[XmlNode](/reference/servoyextensions/server-plugins/xmlreader/xmlnode.md),

## Methods Summarized

| Type                                                   | Name                                                                       | Summary                              |
| ------------------------------------------------------ | -------------------------------------------------------------------------- | ------------------------------------ |
| [Array](/reference/servoycore/dev-api/js-lib/array.md) | [readXmlDocumentFromFile(argument)](#readxmldocumentfromfile-argument)     | Reads an XML document from a file.   |
| [Array](/reference/servoycore/dev-api/js-lib/array.md) | [readXmlDocumentFromString(argument)](#readxmldocumentfromstring-argument) | Reads an XML document from a string. |

## Methods Detailed

### readXmlDocumentFromFile(argument)

Reads an XML document from a file.

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **argument** ;

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) An array of XmlNode objects representing the parsed XML document read from the file.

**Sample**

```js
// specifies a reference to a file containing valid XML
var xmlNodes = plugins.XmlReader.readXmlDocumentFromFile('c:/test.xml');
var childNodes = xmlNodes[0].getChildNodes();
// shows a dialog to open an xml file, then reads the file
var xmlFile = plugins.file.showFileOpenDialog(1);
var xmlNodes = plugins.XmlReader.readXmlDocumentFromFile(xmlFile);
var childNodes = xmlNodes[0].getChildNodes();
```

### readXmlDocumentFromString(argument)

Reads an XML document from a string.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **argument** ;

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) An array of XmlNode objects representing the parsed XML document read from the string.

**Sample**

```js
var xmlString = '<books><book price="44.95">' +
'<title>Core Java 1.5</title>' +
'<author>Piet Klerksen</author>' +
'<nrPages>1487</nrPages>' +
'</book>' +
'<book price="59.95">' +
'<title>Developing with Servoy</title>' +
'<author>Cheryl Owens and others</author><nrPages>492</nrPages></book></books>';
var xmlNodes = plugins.XmlReader.readXmlDocumentFromString(xmlString);
```

***


---

# 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://docs.servoy.com/reference/servoyextensions/server-plugins/xmlreader.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.
