1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| var parser, xmlDoc;
//exemple de contenu string
var str_xml = "<Placemark><name>2</name><NB_IND>2</NB_IND><Point><coordinates>-1.000000,50.000000</coordinates></Point></Placemark>";
//en javascript natif
//https://www.w3schools.com/xml/xml_parser.asp
if (window.DOMParser){
parser = new DOMParser();
xmlDoc = parser.parseFromString(str_xml, "text/xml")
}
var valueSearch = xmlDoc.querySelector("NB_IND").childNodes[0].nodeValue;
console.log("valueSearch", valueSearch);
//En jquery
//https://api.jquery.com/jQuery.parseXML/
xmlDoc = $.parseXML(str_xml);
var xml = $(xmlDoc);
var valueSearch = xml.find("NB_IND").text();
console.log("valueSearch", valueSearch); |
Partager