<html>
<body>
<script type="text/javascript">
text="<bookstore>"
text=text+"<book>";
text=text+"<title>XML</title>";
text=text+"<author>LMJ</author>";
text=text+"<year>2009</year>";
text=text+"</book>";
text=text+"</bookstore>";
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(text);
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.其他浏览器
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(text,"text/xml");
}
catch(e) {alert(e.message)}
}
document.write("xmlDoc is loaded, ready for use");
</script>
</body>
</html>
解析 XML 字符串 - 一个跨浏览器的实例
最新推荐文章于 2024-08-12 23:01:19 发布