Parsing of XML is fairly straightforward with vRO, however there is one major gotcha you should be aware of; namespaces.
Depending on the XML content that vRO is trying to parse it may not return any values if certain namespaces are used. One way around this is to do a string.replace on the xml prior to parsing it.
An example of how to parse XML is shown below:
The code below is based on the following XML
<?xml version="1.0" encoding="UTF-8"?> <CreateITDCIResponse xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2016-06-22T13:07:11+00:00" transLanguage="EN" baseLanguage="EN" messageID="1466600831635951728" maximoVersion="7 1 20110105-1024 V7118-37"><ITDCISet> <CI> <CHANGEBY>Someuser</CHANGEBY> <CHANGEDATE>2016-06-22T13:07:11+00:00</CHANGEDATE> <CIID>123456</CIID> <CINAME>CINAMETEST</CINAME> <CINUM>CITEST</CINUM> <ITDCIMANAGEDBY>TBD</ITDCIMANAGEDBY> <ITDCIOPERATINGENV>TBD</ITDCIOPERATINGENV> <ITDSERVCONTPLAN>0</ITDSERVCONTPLAN> <STATUS>VERIFY</STATUS> <STATUSDATE>2016-06-22T13:07:11+00:00</STATUSDATE> </CI> </ITDCISet> </CreateITDCIResponse>
And this is the vRO code used to extract a specific field, in this case the CIID
// Strip out the namespace definition as vRO doesn't handle the definitions very well var modifiedXMLString = xmlString.replace('xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"',""); var parsedXML = new XML(modifiedXMLString) // Check to see whether we have any content if (!parsedXML) { var errorCode = "Invalid XML Document"; throw "Invalid XML document"; } // Validate that only 1 CI has been returned if (parsedXML.ITDCISet.CI.length() != 1) { var errorCode = "Invalid number of CIs returned"; throw "Invalid number of CIs returned"; } else { for each (CI in parsedXML.ITDCISet.CI) { System.log("The CI number is: " + CI.CIID); } }
Leave a Reply