lonsomehell

xml Script

Feb 23rd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.83 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4.  
  5. function loadXMLDoc(dname) {
  6.     if (window.XMLHttpRequest) {
  7.         xhttp = new XMLHttpRequest();
  8.     } else {
  9.         xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  10.     }
  11.     xhttp.open("GET", dname, false);
  12.     xhttp.send();
  13.     return xhttp.responseXML;
  14. }
  15.  
  16. function loadXMLString(txt) {
  17.     if (window.DOMParser) {
  18.         parser = new DOMParser();
  19.         xmlDoc = parser.parseFromString(txt, "text/xml");
  20.     } else // Internet Explorer
  21.     {
  22.         xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  23.         xmlDoc.async = "false";
  24.         xmlDoc.loadXML(txt);
  25.     }
  26.     return xmlDoc;
  27. }
  28.  
  29. function getProduct(xmlProduit){
  30.     /*
  31.      * Works in firefox.(firefox treats whitespaces as child nodes).
  32.      * ie don't.
  33.      * google chrome (i don't know yet).
  34.      */
  35.    
  36.     product = new Array();
  37.     product.push(xmlProduit.getElementsByTagName("produit")[0].childNodes[1].childNodes[0].nodeValue);
  38.     product.push(xmlProduit.getElementsByTagName("produit")[0].childNodes[3].childNodes[0].nodeValue);
  39.     product[2] = xmlProduit.getElementsByTagName("produit")[0].childNodes[5].childNodes[0].nodeValue;
  40.     return product;
  41. }
  42.  
  43. function showProduct(product){
  44.     document.write("<p>" + product[0] + "</p>");
  45.     document.write("<p>" + product[1] + "</p>");
  46.     document.write("<p>" + product[2] + "</p>");
  47. }
  48.  
  49. function getAllProducts(xmlProduit){
  50.     /*
  51.      * For firefox for now
  52.      */
  53.     xmlProducts = new Array();
  54.     xmlProducts = xmlProduit.getElementsByTagName("produit");
  55.     return xmlProducts;
  56. }
  57.  
  58. function getProductFromArray(pos,products){
  59.     product = new Array();
  60.     product[0] = products[pos].childNodes[1].childNodes[0].nodeValue;
  61.     product[1] = products[pos].childNodes[3].childNodes[0].nodeValue;
  62.     product[2] = products[pos].childNodes[5].childNodes[0].nodeValue;
  63.     return product;
  64. }
  65.  
  66. function showAllProducts(products){
  67.     for(i = 0; i < products.length ; i++){
  68.         showProduct(getProductFromArray(i, products))
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment