var xmlStr ="<data><0>A</0></data>";
if (window.ActiveXObject) {
xd = new ActiveXObject("Microsoft.XMLDOM");
xd.async = false; xd.loadXML(xmlStr);
else if (typeof DOMParser != "undefined")
xd = new DOMParser().parseFromString(xmlStr, "text/xml");
var elem = xd.firstChild;
alert("firstChild is null");
alert(elem.xml || (new XMLSerializer()).serializeToString(elem));
IE:
傳回null
Firefox:
得到<?xml-stylesheet href="chrome://global/locale/intl.css" type="text/css"?>
Chrome/Safari:
<data><parsererror xmlns="http://www.w3.org/1999/xhtml" style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 1 at column 8: StartTag: invalid element name
</div><h3>Below is a rendering of the page up to the first error.</h3></parsererror></data>
Opera:
<parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml">Error<sourcetext>Unknown source</sourcetext></parsererror>