Hello All,
I changed the vRO output (Which I was getting from powershell) in XML format by using ".getxml" . Now I want to parse and extract the from that xml format. Could anyone help to to write javascript program for this?
Hi,
The easiest way to work with XML in Javascript is via E4X (ECMAScript for XML) - https://developer.mozilla.org/en-US/docs/Archive/Web/E4X
So basically all you need is to create a document instance passing your XML string as an argument, and then you'll be able to navigate/process the XML content using E4X syntax.
I guess you refer to PowerShellRemotePSObject.getXml() function. If that is the case there are few utility classes comming with the plugin wich can help you to work wit result from powershell plugin.
There is sample workflow demonstrating how to extract values from .ps script output distributed with the plugin itself "Library/PowerShell/Samples/List directory content"
I usually use getXml()/getJson methods to get general knowledge of the structure of the returned result (what kind of objects are returned arrays,maps,simple types, complex objects and available properties ) . This info can also be found by looking at power-shell help .
Once I know what kind of objects are returned by the script you can use PowerShellRemotePSObject.getRootObject() and
a) if it is an array than the call to PowerShellRemotePSObject.getRootObject() will return javascript Array object and you can process it as normal js array
b) if it is simple type (string/int ..) it is mapped to js simple type
c) if it is a complex object then use .getProperty() to access particular object properties
...
vSphere 5.5 Documentation Center
If you post some example xml returned I can provide some examples for extracting values from it.
Hope it helps!