Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Most examples on the web (and some presented above) show how to load an XML <strong>from a file</strong> in a browser compatible manner. This proves easy, except in the case of Google Chrome which does not support the <code>document.implementation.createDocument()</code> method. When using Chrome, in order to load an XML file into a XmlDocument object, you need to use the inbuilt XmlHttp object and then load the file by passing it's URI.</p> <p>In your case, the scenario is different, because you want to load the XML <strong>from a string variable</strong>, not a URL. For this requirement however, Chrome supposedly works just like Mozilla (or so I've heard) and supports the parseFromString() method.</p> <p>Here is a function I use (it's part of the Browser compatibility library I'm currently building):</p> <pre class="lang-js prettyprint-override"><code>function LoadXMLString(xmlString) { // ObjectExists checks if the passed parameter is not null. // isString (as the name suggests) checks if the type is a valid string. if (ObjectExists(xmlString) &amp;&amp; isString(xmlString)) { var xDoc; // The GetBrowserType function returns a 2-letter code representing // ...the type of browser. var bType = GetBrowserType(); switch(bType) { case "ie": // This actually calls into a function that returns a DOMDocument // on the basis of the MSXML version installed. // Simplified here for illustration. xDoc = new ActiveXObject("MSXML2.DOMDocument") xDoc.async = false; xDoc.loadXML(xmlString); break; default: var dp = new DOMParser(); xDoc = dp.parseFromString(xmlString, "text/xml"); break; } return xDoc; } else return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload