JS Lib XML: reading values not working like wiki example

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:

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?

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

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