PDA

View Full Version : Text to xml



Asken
25 Feb 2011, 3:53 AM
Hi,

I get an XML result from Sharepoint but for some reason they've decided to return my data, which is also valid XML, as a text value in a QueryResult element.

I have no problem using select to retrieve the QueryResult but the rest is text... can I easily convert the text to XML? I want to be able to use DomQuery to get the array of documents in the result but can't as it's not type XML.

What I've found so far:


// Works but it's cheating...
var d = document.createElement('div');
d.innerHTML = result.textContent || result.text;
var array = Ext.DomQuery.select("Results/Document", d);

Asken
25 Feb 2011, 4:49 AM
Found another way... the old-fashioned one:


stringToXml: function(data) {
var xmlDoc = null;
if (window.DOMParser) {
xmlDoc = new DOMParser().parseFromString(data, 'text/xml');
} else {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(data);
}
return xmlDoc;
}

Any other solution is most welcome...