# JS Lib XML: reading values not working like wiki example

**URL:** <https://forum.servoy.com/t/js-lib-xml-reading-values-not-working-like-wiki-example/17341>\
**Category:** Classic Servoy\
**Created:** [July 16, 2013, 10:38am UTC](https://forum.servoy.com/t/js-lib-xml-reading-values-not-working-like-wiki-example/17341 "2013-07-16T10:38:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaptan](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@Kaptan](https://forum.servoy.com/u/Kaptan)\
**Post date:** [July 16, 2013, 10:38am UTC](https://forum.servoy.com/t/js-lib-xml-reading-values-not-working-like-wiki-example/17341/1 "2013-07-16T10:38:57Z")

</div>

While fiddling around with the JS Lib XML/XMLList in reading a XML string, I’ve noticed that the Wiki example doesn’t work (in 6.1.4).

The wiki gives the following example:

```auto
var myXml = new XML('<test level="1"><test2 level="2">A value</test2><test2 level="2">Another value</test2></test>');
application.output(myXml.test2[1]); //outputs 'Another value'

```

(p.s. wiki example has a typo: no quotation around the value of one of the ‘level’ attributes)

following this example, in 6.1.4 (haven’t tested it in other versions) you won’t get the ouput ‘Another value’, but will get a null value.  
adding .toString() will give the expected output.

Bug or incorrect documentation?

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [July 16, 2013, 7:31pm UTC](https://forum.servoy.com/t/js-lib-xml-reading-values-not-working-like-wiki-example/17341/2 "2013-07-16T19:31:28Z")

</div>

The example is a bit wrong indeed: myXml.test2[1] returns the XML node Another value. If you want to output the text content, you indeed need to call .toString() on is, or .toXMLString() if you want to output the entire node.

Paul

---

<div class="post-metadata">

**Author:** ![Kaptan](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@Kaptan](https://forum.servoy.com/u/Kaptan)\
**Post date:** [July 17, 2013, 9:33am UTC](https://forum.servoy.com/t/js-lib-xml-reading-values-not-working-like-wiki-example/17341/3 "2013-07-17T09:33:32Z")

</div>

Thanks, that’s what I thought initially. But the wiki example got me a bit confused.
