[JS]用js解析和加载xml文件实例源代码
[JS]用js来加载xml文件实例源代码
[JS]用js解析和加载xml文件实例源代码
- <html>
- <head>
- <script type="text/javascript">
- function parseXML()
- {
- try //Internet Explorer
- {
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- }
- catch(e)
- {
- try //Firefox, Mozilla, Opera, etc.
- {
- xmlDoc=document.implementation.createDocument("","",null);
- }
- catch(e)
- {
- alert(e.message);
- return;
- }
- }
- xmlDoc.async=false;
- xmlDoc.load("/example/xmle/note.xml");
- document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
- document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
- document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
- }
- </script>
- </head>
- <body onload="parseXML()">
- <h1>W3Schools 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>
XML文件
- <?xml version="1.0" encoding="ISO-8859-1" ?>
- - <note>
- <to>George</to>
- <from>John</from>
- <heading>Reminder</heading>
- <body>Don't forget the meeting!</body>
- </note>
热门文章推荐
- [JS]window.location获取url各项参数详解
- [JS]jQuery,javascript获得网页的高度和宽度
- [JS]视频弹窗视频弹出层videoLightBox(含三种播放器的用法)
- [JS]JS提交中文encodeURI两次转码
- [JS]js版方面encodeURI转码和decodeURI解码的用法实例
- [JS]js取当前机子的时间戳实例
- [JS]AES加密(基于crypto-js)PHP后端解密
- [JS]data:image/png;base64写法的用途及说明
请稍候...