I have 3 files, (htm, xml, js) to work together fine in IE8, but in IE10 the javascript cannot get xml element:
getxml.htm
<html>
<head><title>getxml.htm</title></head>
<xml id="myxml" src="myxml.xml"></xml>
<script src="getxml.js" language="javascript" type="text/javascript"></script>
</html>
myxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<publish>
</publish>
getxml.js
get_xml_content();
function get_xml_content() {
alert("get_xml_content");
alert(myxml); // ie8: [object], ie10: [object HTMLUnknownElement]
var xmle=myxml.getElementsByTagName("publish").item(0);
alert(xmle); // ie8: [object], ie10: null
}
Alert message from IE8 and IE10 are written as comments above in getxml.js.
Appreciate any help, thanks!
According to a blog post at the IEBlog, IE10 does not support XML Data Islands when running in Standards mode. This brings IE10 into conformance with how other browsers parse HTML.
To get this to work in IE10, you need to load the page in legacy mode. You can do that by including the
X-UA-Compatiblemeta tag:A more cross-browser approach would be to link the XML with an
<iframe>instead:Of course, you’ll need to hide it with a bit of CSS:
Reference
contentDocumentto parse the document: