Best way to parse this XML with jQuery

 <?xml version="1.0" encoding="UTF-8" ?>
 <BMC_Impact_Manager version="1.0">
 <IMPACT_EVENT>
  <EVENT>
     <date_reception>1279568162</date_reception> 
  </EVENT>
  <EVENT>
    <date_reception>1279568162</date_reception> 
  </EVENT>
  <EVENT>
    <date_reception>1279568102</date_reception> 
  </EVENT>
  <EVENT>
    <date_reception>1279567862</date_reception> 
  </EVENT>
  <EVENT>
    <date_reception>1279567836</date_reception> 
  </EVENT>
</IMPACT_EVENT>

We changed the XML output to look like this ... now I no longer need help ... Thanks, though!

0
source share
3 answers

Use your own XML parser.

// http://www.w3schools.com/dom/dom_parser.asp
function parseXML(text) {
    var doc;

    if(window.DOMParser) {
        var parser = new DOMParser();
        doc = parser.parseFromString(text, "text/xml");
    }
    else if(window.ActiveXObject) {
        doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async = "false";
        doc.loadXML(text);
    }
    else {
        throw new Error("Cannot parse XML");
    }

    return doc;
}

Then get all the receive admission tags as

var xml = parseXML(xmlString);
$(xml).find('date_reception').each(function() {
    console.log(this.text());
});
+3
source

Here is a simple Javascript example for parsing, a very simple example: http://www.captain.at/howto-ajax-xml-javascript.php

0
source

Assuming you have xml as a string, then it should only be:

var xml = ".....";
val values = $("date_reception", $(xml))
0
source

All Articles