[英]Xpath incompatible with Internet Explorer
I am trying to extract XML with XPath. 我正在尝试使用XPath提取XML。 It works well with Firefox and Chrome, but, it doesn't work with IE9. 它与Firefox和Chrome兼容,但与IE9不兼容。 Is there some trick or a hack I should do? 我应该采取一些技巧或技巧吗? You can see it here . 你可以在这里看到它。
Here is the HTML: 这是HTML:
<!DOCTYPE html>
<html>
<body>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
//xml=loadXMLDoc("productfeed-production-version_sample.xml");
xml=loadXMLDoc("data.xml");
//path="/Products/Product/Category"
path="root/article[3]/Price"
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].childNodes[0].nodeValue);
document.write("<br>");
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();
while (result)
{
document.write(result.childNodes[0].nodeValue);
document.write("<br>");
result=nodes.iterateNext();
}
}
</script>
</body>
</html>
Here is the XML file: 这是XML文件:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<article>
<title>Best of the West - Édition Été 2013</title>
<description>Un voyage dans l'Ouest américain est sans aucun doute ce qu'il y a de mieux pour qui veut se rendre aux Etats-Unis! Vous y transiterez par trois des villes les plus branchées...</description>
<url>http://www.connections.be</url>
<urltext>Visit the Site: connections.be</urltext>
<Price>199,99</Price>
</article>
<article>
<title>Hôtel Yotel</title>
<description>Prenez le concept des hôtels capsule japonais, ajoutez-y le meilleur de la première classe des avions, saupoudrez le tout avec un style urbain et tendance,...</description>
<url>http://www.connections.be</url>
<urltext>Learn more</urltext>
<Price>199,99</Price>
</article>
<article>
<title>Essential Thailand</title>
<description>Ce programme individuel, idéal pour un premier voyage en Thaïlande, vous emmène à la découverte des points d'orgue de Bangkok et de Chiang Mai.</description>
<url>http://www.connections.be</url>
<urltext>Continue Reading...</urltext>
<Price>199,99</Price>
</article>
</root>
You need to use one of the following recommended XPath libraries in order for XPath to work in IE: 您需要使用以下推荐的XPath库之一,才能使XPath在IE中运行:
JavaScript-XPath (I use this one)
Update : This is now defunct, an archived version from late 2016 can be seen in the Internet Archive.
JavaScript-XPath (我使用的是此
更新) :现在已不存在,可以在Internet存档中看到2016年末的存档版本 。
wicked-good-xpath - This is a re-implementation JavaScript-XPath by Google, faster and with a smaller code size. wicked-good-xpath-这是Google重新实现的JavaScript-XPath,速度更快且代码大小更小。
jquery-xpath - A jQuery extension with XPath 2.0 support. jquery-xpath-具有XPath 2.0支持的jQuery扩展。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.