$().SPXmlToJson and Search...

Dec 16, 2014 at 4:21 PM
Hi Marc. Will you be expanding its functionality to work with calls to search.asmx? The XML SPServices returns is much more usable than the raw XML that comes back from search.asmx, and adding conversion to JSON would be a realy nice to have (without needing another 3rd party library).

Thanks!
Chris
Coordinator
Dec 18, 2014 at 10:53 AM
Edited Dec 18, 2014 at 10:53 AM
SPServices simply returns the XML that the SOAP operation returns. You probably mean that you'd rather get JSON back from calls to Search? $().SPXmlToJson as it currently works only will process "flat" XML, like that which comes back from GetListItems.

Could you be a little more specific about what you want? It sounds like a good addition. Also, what version of SharePoint are you using?

M.
Dec 18, 2014 at 11:45 PM
Hi Marc, thanks for getting back to me.

The XML returned by search.asmx directly and via SPServices are subtly different. In the direct call, all the <Document xmlns="urn:Microsoft.Search.Response.Document"> elements are nested within each other, whereas via SPServices, they are siblings, so it seems SPServices is doing some manipulation already.

This...
<Property>
  <Name>TITLE</Name>
  <Type>String</Type>
  <Value>This is the page title.</Value>
</Property>
<Property>
  <Name>PATH</Name>
  <Type>String</Type>
  <Value>
  http://domainwhatever.edc.ca/path/filename.aspx</Value>
</Property>
<Property>
  <Name>DESCRIPTION</Name>
  <Type>String</Type>
  <Value>This is a fine description</Value>
</Property>
<Property>
  <Name>HOSTVIDEOID</Name>
  <Type>String</Type>
  <Value>B0ZOC5oGMVQ</Value>
</Property>
<Property>
  <Name>DURATION</Name>
  <Type>String</Type>
  <Value>00:05:59</Value>
</Property>
<Property>
  <Name>EVENTSTARTDATE</Name>
  <Type>DateTime</Type>
  <Value>2014-11-20T05:00:00</Value>
</Property>
</Properties>
...could become:
{ Properties:
  { "TITLE": { "Value": "This is the page title", "Type": "String" }, "PATH": { "Value: "http://domainwhatever.edc.ca/path/filename.aspx", "Type": "String" }, ...  etc. }
}
You'd probably need to loop through each Document and Property, and it may not be terribly efficient. I'm basically doing this now, except I know which properties I'm looking for, so it's 'fast enough'. The .then of the jQuery promise builds the JSON, and it sure would be convenient to just call .SPXmlToJson() on it.

Chris