加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 20:04:29 所属栏目:PHP教程 来源:网络整理
导读:!--解析XML字符串,跨阅读器实例-- html head script type = text/javascript function parseXML() { text = note; text = toGeorge/to; text = fromJhon/from; text = text headingReminder/heading; text = text bodyDon't forget/body; text = text /note
<!--解析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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读