Generate XML with SOAP API

(imported topic written by SystemAdmin)

I am experimenting with the SOAP API, and I am surprised at how limited it is, or perhaps how limited I am.

I have a relevance query that returns multiple properties for computers that meet certain criteria. For example, the name, IP(s), and last update time of bes computers whose name contains “12345”. (the actual query is much longer and difficult to read)

The query works fine, however each computer is wrapped in a single tag in the returned XML, making it impossible to use any XML parsing tools to process the output.

I have tried manually inserting the tags by doing: …"" & item 0 of it & “”… but the XML results simply replace the greater and less than symbols with < and > as expected.

How do I get the results in XML format for example:

<a> <computerName>myPCname</computerName> <ipAddress>1.2.3.4</ipAddress> <lastUpdate>9/23/09 5:30pm</lastUpdate> </a> <a> <computerName>anotherPCname</computerName> ...

(imported comment written by BenKus)

Hey jfry,

Yes. Currently in the SOAP API, the return data isn’t typed. Try returning the data on a single line with a delimiter and then parse the data… such as:

(name of it & “—” & ip address of it as string) of bes computers

Ben

(imported comment written by SystemAdmin)

If anyone would like a way to transform their results to XML below is a javascript function I use to do it (IE ONLY!). In my query I wrap the results in tags like:

relevance = 
'(("<computername>" & item 0 of it & "</computername><servicetag>" & item 1 of it...

Then I remove the special characters from my relevance query before submitting it with a function like this (the query will fail if you don’t do this step):

function replaceSpecialCharacters(specialstring) 
{ specialstring = specialstring.replace(/&/g,
"&"); specialstring = specialstring.replace(/
"/g,"
""); specialstring = specialstring.replace(/</g,
"<"); specialstring = specialstring.replace(/>/g,
">"); specialstring = specialstring.replace(/
'/g,"'
"); 

return specialstring; 
}

Finally, I process the results with the following function, which converts the returned XML object to a string, restores the special characters, then returns a new xml object that now has typed data.

function rebuildXML(xmlObject) 
{ 
//convert result to string for replacements of special characters xmlString = xmlObject.responseXML.xml xmlString = xmlString.replace(/&/g,
"&"); xmlString = xmlString.replace(/
"/g,"\
""); xmlString = xmlString.replace(/</g,
"<"); xmlString = xmlString.replace(/>/g,
">"); xmlString = xmlString.replace(/
'/g,"'
"); 
//convert back to XML file, now with tags around each value rebuiltXML=

new ActiveXObject(
"Microsoft.XMLDOM"); rebuiltXML.async=
"false"; rebuiltXML.loadXML(xmlString); 

return rebuiltXML; 
}