Parse html / text document as XML?

How can I parse a document with a text / html heading as an XML document using jQuery?

+3
source share
2 answers
xmlString = ""; //GET string via ajax or whatever the case might be

if (window.DOMParser){
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(xmlString,"text/xml");
}
else {  // For IE
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(xmlString); 
}

Hope this helps.

+1
source

use ajax request to get page data and treat it as text data.

$.get(URL, params, function(data) {

    //process the data here

});
+2
source

Source: https://habr.com/ru/post/1766725/


All Articles