# XmlNode

## Overview

XML nodes are structured elements that support interaction and manipulation through various methods. These methods facilitate operations such as retrieving attribute names and values, accessing child nodes, obtaining the node name and type, and fetching the text value of an XML node.

## Functionality

The `getAttributeNames` method retrieves all attribute names from the current node, while `getAttributeValue` returns the value of a specified attribute. To interact with node relationships, `getChildNodes` allows access to all child nodes. Additionally, `getName` provides the name of the XML node, and `getType` identifies its type. For textual data, `getTextValue` extracts the text content of the node.

## Methods Summarized

| Type                                                     | Name                                                                 | Summary                                             |
| -------------------------------------------------------- | -------------------------------------------------------------------- | --------------------------------------------------- |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)   | [getAttributeNames()](#getattributenames)                            | Return all the attribute names of the current node. |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [getAttributeValue(attributeName)](#getattributevalue-attributename) | Return the value of the named attribute.            |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)   | [getChildNodes()](#getchildnodes)                                    | Return the child nodes of the current node.         |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [getName()](#getname)                                                | Return the name of the XML node element.            |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [getTextValue()](#gettextvalue)                                      | Return the text-value of the XML node element.      |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [getType()](#gettype)                                                | Return the type of the XML node element.            |

## Methods Detailed

### getAttributeNames()

Return all the attribute names of the current node.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) an array of attribute names for the current XML node, or an empty array if the node has no attributes.

**Sample**

```js
nodes = plugins.XmlReader.readXmlDocumentFromString("<root attr1='value1' attr2='value2'/>")
rootNode = nodes[0];
attributes = rootNode.getAttributeNames();
application.output(attributes[0])
application.output(attributes[1])
val1 = rootNode.getAttributeValue('attr1');
application.output(val1)
```

### getAttributeValue(attributeName)

Return the value of the named attribute.

**Parameters**

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

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the value of the specified attribute, or null if the attribute does not exist.

**Sample**

```js
nodes = plugins.XmlReader.readXmlDocumentFromString("<root attr1='value1' attr2='value2'/>")
rootNode = nodes[0];
attributes = rootNode.getAttributeNames();
application.output(attributes[0])
application.output(attributes[1])
val1 = rootNode.getAttributeValue('attr1');
application.output(val1)
```

### getChildNodes()

Return the child nodes of the current node.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) an array of XmlNode objects representing the child nodes of the current XML node, or an empty array if there are no child nodes.

**Sample**

```js
nodes = plugins.XmlReader.readXmlDocumentFromString('<father><child1>John</child1><child2>Mary</child2></father>');
application.output(nodes[0].getName())
application.output(nodes[0].getTextValue())
application.output(nodes[0].getType())
childs = nodes[0].getChildNodes()
application.output(childs[0].getName())
application.output(childs[0].getTextValue())
application.output(childs[0].getType())
subChilds = childs[0].getChildNodes()
application.output(subChilds[0].getName())
application.output(subChilds[0].getTextValue())
application.output(subChilds[0].getType())
```

### getName()

Return the name of the XML node element.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the name of the XML node element.

**Sample**

```js
nodes = plugins.XmlReader.readXmlDocumentFromString('<father><child1>John</child1><child2>Mary</child2></father>');
application.output(nodes[0].getName())
application.output(nodes[0].getTextValue())
application.output(nodes[0].getType())
childs = nodes[0].getChildNodes()
application.output(childs[0].getName())
application.output(childs[0].getTextValue())
application.output(childs[0].getType())
subChilds = childs[0].getChildNodes()
application.output(subChilds[0].getName())
application.output(subChilds[0].getTextValue())
application.output(subChilds[0].getType())
```

### getTextValue()

Return the text-value of the XML node element.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the text value of the XML node element, or null if the node has no text content.

**Sample**

```js
nodes = plugins.XmlReader.readXmlDocumentFromString('<father><child1>John</child1><child2>Mary</child2></father>');
application.output(nodes[0].getName())
application.output(nodes[0].getTextValue())
application.output(nodes[0].getType())
childs = nodes[0].getChildNodes()
application.output(childs[0].getName())
application.output(childs[0].getTextValue())
application.output(childs[0].getType())
subChilds = childs[0].getChildNodes()
application.output(subChilds[0].getName())
application.output(subChilds[0].getTextValue())
application.output(subChilds[0].getType())
```

### getType()

Return the type of the XML node element.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the type of the XML node element, which can be "TEXT", "ELEMENT", or "UNKNOWN".

**Sample**

```js
nodes = plugins.XmlReader.readXmlDocumentFromString('<father><child1>John</child1><child2>Mary</child2></father>');
application.output(nodes[0].getName())
application.output(nodes[0].getTextValue())
application.output(nodes[0].getType())
childs = nodes[0].getChildNodes()
application.output(childs[0].getName())
application.output(childs[0].getTextValue())
application.output(childs[0].getType())
subChilds = childs[0].getChildNodes()
application.output(subChilds[0].getName())
application.output(subChilds[0].getTextValue())
application.output(subChilds[0].getType())
```

***


---

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