---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# XMLNodeIterator - Scoped

# XMLNodeIterator - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

The XMLNodeIterator API provides methods to iterate through a node of a XML document.

There are no constructors for creating a stand alone instance of a XMLNodeIterator object. To create a XMLNodeIterator object use the getChildNodeIterator() method of the [XMLNode object](https://servicenow-prod.fluidtopics.net/zTmJmTkyLexYKVyMUsUqtw#c_XMLNodeScopedAPI "The XMLNode API provides methods to query values from XML nodes. XMLNodes are extracted from XMLDocument2 objects, which contain XML strings.").

## XMLNodeIterator - hasNext() {#ariaid-title2}

Returns true if the iteration has more elements.
{#r_ScopedXMLNodeIteratorHasNext__table_d2h_pfc_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#r_ScopedXMLNodeIteratorHasNext__table_d2h_pfc_2r} {#r_ScopedXMLNodeIteratorHasNext__table_dcg_pg5_1r__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the iteration has more elements. |
[Table 2. Returns]

{#r_ScopedXMLNodeIteratorHasNext__table_dcg_pg5_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//one');
    var iter= node.getChildNodeIterator();
    gs.info(iter.hasNext());

## XMLNodeIterator - next() {#ariaid-title3}

Gets the next element in the iteration. The returned element may be a #text node for
the spaces/tabs if XML is "pretty formatted".
{#r_ScopedXMLNodeIteratorNext__table_asl_4fc_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#r_ScopedXMLNodeIteratorNext__table_asl_4fc_2r} {#r_ScopedXMLNodeIteratorNext__table_dnj_dh5_1r__entry__2}

| Type | Description |
|-|-|
| XMLNode | The next element in the iteration. |
[Table 4. Returns]

{#r_ScopedXMLNodeIteratorNext__table_dnj_dh5_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//one');
    var iter= node.getChildNodeIterator();
    while(iter.hasNext()) {
       var n = iter.next();
       gs.info('Node name: ' +  n.getNodeName());
       gs.info('Node value: ' +  n.getNodeValue());
    }

Output:

    Node name: #text
    Node value:     
    Node name: two
    Node value: null
    Node name: #text
    Node value:     
    Node name: three
    Node value: null
    Node name: #text
    Node value:     
    Node name: two
    Node value: null
    Node name: #text
    Node value:


