国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > php教程 > 解析XML字符串,跨浏览器实例

解析XML字符串,跨浏览器实例

来源:程序员人生   发布时间:2015-04-02 08:50:02 阅读次数:3498次
<!--解析XML字符串,跨阅读器实例-->
<html>
<head>
<script type = "text/javascript">
function parseXML()
{
text = "<note>";
text = "<to>George</to>";
text = "<from>Jhon</from>";
text = text + "<heading>Reminder</heading>";
text = text + "<body>Don't forget</body>";
text = text + "</note>";
try
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(text);
}
catch(e)
{
try
{
parser = new DOMParser();
xmlDoc = parser.parseFromString(text, "text/html");
}
catch(e)
{
alter(e.message);
return;
}


}


document.getElementById("to").innerHTML = xmlDoc/getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML = xmlDoc.getELementsByTagName("from")[0].nodeNodes[0].nodeValue;
document.getElementById("message").innerHTML = xmlDoc.getElementsByTagName("Body")[0].childNodes[0].nodeValue;
}
</script>
</head>
<body onload = "parseXML">
<h1>W3School.com.cn Internal Note</h1>
<p>
<b>To:</b> <span id = "to"></span><br />
<b>From:</b> <span id = "from"></span><br />
<b>Message:</b> <span id = "message"></span>
</p>
</body>
</html>
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生