Guest User

Untitled

a guest
Feb 17th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* script.js */
  2.  
  3. /* FUNCTIONS */
  4.  
  5. // HTTP Request
  6. function loadXML (file) {
  7.     if (window.XMLHttpRequest) {
  8.         // code for Chrome, Firefox, Opera, etc.
  9.         xhttp = new XMLHttpRequest();
  10.     } else {
  11.         // code for IE
  12.         xhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Different ActiveXObject for IE
  13.     };
  14.     xhttp.open("GET", file, false);
  15.     try {xhttp.responseType = "msxml-document";} catch (e) {}; // Set responseType for IE 9+
  16.     xhttp.send(null);
  17.     return xhttp.responseXML;
  18. };
  19.  
  20. // Process & Output
  21. function processXML (location, xml, xsl) {
  22.     if (window.ActiveXObject || xhttp.responseType == "msxml-document" || "ActiveXObject" in window) { // Added criteria for IE detection
  23.         // code for IE
  24.         ex = xml.transformNode(xsl);
  25.         document.getElementById(location).innerHTML = ex;
  26.     } else if (document.implementation && document.implementation.createDocument) {
  27.         // code for Chrome, Firefox, Opera, etc.
  28.         xsltProcessor = new XSLTProcessor();
  29.         xsltProcessor.importStylesheet(xsl);
  30.         resultDocument = xsltProcessor.transformToFragment(xml, document);
  31.         document.getElementById(location).innerHTML = '';
  32.         document.getElementById(location).appendChild(resultDocument);
  33.     };
  34. };
  35.  
  36. // HTTP Request, Process & Output
  37. function outputXML(location, xmlFile, xslFile) {
  38.     xml = loadXML(xmlFile);
  39.     xsl = loadXML(xslFile);
  40.     processXML(location, xml, xsl);
  41. };
  42.  
  43. // Parse XML to String
  44. function XMLToString(xml) {
  45.     if (window.ActiveXObject) {
  46.         // code for IE
  47.         var txt = xml.xml;
  48.         return txt;
  49.     } else {
  50.         // code for Chrome, Firefox, Opera, etc.
  51.         var txt = new XMLSerializer();
  52.         txt = txt.serializeToString(xml);
  53.         return txt;
  54.     };
  55. };
  56.  
  57. // Parse String to XML
  58. function StringToXML(txt) {
  59.     if (window.DOMParser) {
  60.         // code for Chrome, Firefox, Opera, etc.
  61.         parser=new DOMParser();
  62.         xml=parser.parseFromString(txt,"text/xml");
  63.     } else {
  64.         // code for IE
  65.         xml=new ActiveXObject("Microsoft.XMLDOM");
  66.         xml.async=false;
  67.         xml.loadXML(txt);
  68.     };
  69.     return xml;
  70. };
Add Comment
Please, Sign In to add comment