VMware Cloud Community
segadson
Contributor
Contributor
Jump to solution

HTTP Rest Response

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?

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

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

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
5 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

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

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

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

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

.. 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.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

:smileyblush::smileyblush: I should have stated that, yes :smileysilly:

0 Kudos
segadson
Contributor
Contributor
Jump to solution

Thanks Guys for your Help!

0 Kudos