Hello,
I am currently trying to handle a HTTP rest Response that has xml that isnt neccessarliy elements that can easily be parsed: Below is the XML Extrack:
<?xml version="1.0" encoding="ISO-8859-1"?><TopologyElements>
<TopologyElement accessSpeedConsumed="0.0" cpuConsumedFactor="0.0" creationClassName="VirtualMachineProfile" description="myCompute" displayName="SeanTest1" ioThroughputConsumed="0.0" memConsumedFactor="0.0" model="" name="VirtualMachine::SeanTest1" networkThroughputConsumed="0.0" numVCPUs="1" price="0.0" services="" storageConsumedFactor="0.0" uuid="_A0pIIPJ2EeSlaNuNHq7FiA" vMemSize="1048576.0" vStorageSize="4096.0" vendor="VSI"/>
</TopologyElements>
Is there a best way to parse this data?
Assuming you place that string in a variable named "xmlString", E4X would be simple to parse with. For example, to get the description property from your element:
var xmlDoc = new XML(xmlString);
default xml namespace = xmlDoc.namespace();
var description = xmlDoc..*::TopologyElement.@*::description.toString();
System.debug("Description: "+description);
Here's the output I received when I ran that:
[2015-05-04 12:33:42.287] [D] Description: myCompute
Assuming you place that string in a variable named "xmlString", E4X would be simple to parse with. For example, to get the description property from your element:
var xmlDoc = new XML(xmlString);
default xml namespace = xmlDoc.namespace();
var description = xmlDoc..*::TopologyElement.@*::description.toString();
System.debug("Description: "+description);
Here's the output I received when I ran that:
[2015-05-04 12:33:42.287] [D] Description: myCompute
Also, check this thread to avoid a neat pitfall when passing the parsed results to workflow attributes:
https://communities.vmware.com/thread/509784
Cheers,
Joerg
.. just so there is no confusion, Joerg points out a good item in that thread, but my code already takes that into account and uses the .toString() method to ensure you have the string value that may be bound to attributes.
:smileyblush::smileyblush: I should have stated that, yes :smileysilly:
Thanks Guys for your Help!