views:

77

answers:

3
 <?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... so now I no longer need help... Thanks though!

+3  A: 

Use a proper 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 date reception tag values as

var xml = parseXML(xmlString);
$(xml).find('date_reception').each(function() {
    console.log(this.text());
});
Anurag
There is more than just "date_reception" though, there are 8 more tags in each event. I just put "date_reception" so the XMl would look more simple.
Mark Cheek
@Mark - Update your question with your XML and where you are stuck. It's hard to tell from your comment how to further proceed.
Anurag
A: 

Here is an example of just Javascript to parse, very simple example: http://www.captain.at/howto-ajax-xml-javascript.php

Mark Schultheiss
A: 

Assuming you've got the xml as a string, then it should just be:

var xml = ".....";
val values = $("date_reception", $(xml))
James Curran