分享

javascript解析xml文件二

 明天网吧 2015-07-14
html文件:
<html>
<head>
<script type="text/javascript">
function parseXML()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.open("GET","class.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 
xmlDoc.async=false;

var val=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
alert(val);
}
</script>
</head>

<body onload="parseXML()">

</body>
</html>


class.xml
<?xml version="1.0" encoding="utf-8"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多