We have been using the XML plugin to read the response and create requests for REST operations, and it has been working pretty well until some new rest calls. We are now getting back XML that contains a periods in the node names. We can’t figure out how to read this. Here is a simple example, because there is a period between node.one I cannot seem to get the value for ID. I tried using a \ as an escape character for the period, but vCO throws an exception.
Any help would be greatly appreciated.
contentAsString = <root>
<node.one>
<id>5</id>
</node.one>
</root>;
contentAsString = contentAsString.toString();
xmldocument = new XML(contentAsString);
System.log("Total Machine Count: " + xmldocument.node.one.id);
Note: if I take the period out of node.one it will work just fine, but I don't have any control of the XML I'm getting, so I cannot do that.
Hi,
You can try with the XMLManager and its related scripting objects, and with this (a little bit more verbose) approach:
var document = XMLManager.fromString(contentAsString).getDocumentElement();
var count = document.getElementsByTagName("node.one").item(0).getElementsByTagName("id").item(0).textContent;
System.log("Total Machine Count: " + count);
The problem with the direct approach is that in the line with the scripting code "xmldocument.node.one.id" it's not possible to say if "one" is part of the node name ("node.one") or it's a property of the node "node" (again "node.one"). The same occurs if instead of a period (".") you have an hyphen ("-") for example, since inside the scripting it would be interpreted as a subtraction of two variables. But if you had an underscore ("_") it should work.
I hope it helps.
Sergio
Hi,
You can try with the XMLManager and its related scripting objects, and with this (a little bit more verbose) approach:
var document = XMLManager.fromString(contentAsString).getDocumentElement();
var count = document.getElementsByTagName("node.one").item(0).getElementsByTagName("id").item(0).textContent;
System.log("Total Machine Count: " + count);
The problem with the direct approach is that in the line with the scripting code "xmldocument.node.one.id" it's not possible to say if "one" is part of the node name ("node.one") or it's a property of the node "node" (again "node.one"). The same occurs if instead of a period (".") you have an hyphen ("-") for example, since inside the scripting it would be interpreted as a subtraction of two variables. But if you had an underscore ("_") it should work.
I hope it helps.
Sergio
I like to use E4X DOM like capabilities so you get the best of both worlds:
System.log("Total Machine Count: " + xmldocument.child("node.one").id);
Christophe.
Thanks Sergio. It's an useful piece of information.