xml文件:test.xml

<?xml version="1.0"?>  

<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
<lastname>Simth</lastname> </note>

html文件:

<html>  

<head>  

    <script type="text/javascript">  

        function parseXML(){  

            try{  

                xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
}catch(e){ try{ xmlDoc= document.implementation.createDocument("","",null);
}catch(e){ alert(e.message);
return;
}
}
xmlDoc.async = false;
xmlDoc.load("../xml/test.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>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>

[HTML]js读取XML文件并解析的更多相关文章

  1. JAVA读取XML文件并解析获取元素、属性值、子元素信息

    JAVA读取XML文件并解析获取元素.属性值.子元素信息 关键字 XML读取  InputStream   DocumentBuilderFactory   Element     Node 前言 最 ...

  2. Js读取XML文件为List结构

    习惯了C#的List集合,对于Javascript没有list 极为不舒服,在一个利用Js读取XML文件的Demo中,决定自己构建List对象,将数据存入List. 第一步,Js读取XML文件知识 X ...

  3. IE下JS读取xml文件示例代码

    JS读取xml文件具体步骤为:创建DOM对象.加载xml文件(仅适用于IE)附示例代码,感兴趣的朋友可以参考下,希望对大家有所帮助使用javascript脚本读取xml文件,这里暂只考虑IE浏览器st ...

  4. jQuery、JS读取xml文件里的内容(JS先通过document.implementation.createDocument方法将xml转换成document对象,jQuery将读取到的xml转成table)

    xml文件:test.xml <?xml version="1.0"?> <note> <to>George</to> <fr ...

  5. js 读取xml文件

    读取xml文件 [原创 2007-6-20 17:35:37]     字号:大 中 小 js中读取xml文件,简单的例子: <html><head><script> ...

  6. JS读取XML文件数据并以table显示数据(兼容IE火狐)

    先看xml文件: <?xml version="1.0" standalone="yes"?> <student> <stuinf ...

  7. MFC读取XML文件并解析

    现在经常会对XML文件进行操作,怎么在MFC下去读和解析XML文件呢?直接上代码: 首先得等在stdafx.h中加入这句,以引入MSXML命名空间 #import <msxml3.dll> ...

  8. js读取xml文件

    假设我们现在要读取下面的 info.xml 文件 <?xml version="1.0" encoding="gb2312"?> <root& ...

  9. 【JavaScript】JS读取XML文件并进行搜索

    需求效果 点击链接.当前页面载入xml文件并展示相应内容 通过搜索框.搜索xml文件内节点数据.展示包括内容的节点数据 功能实现 Demo终于实现效果 http://loadxmldemo.coder ...

随机推荐

  1. Kattis之旅——Inverse Factorial

    题目意思就是已知n的阶乘,求n. 当输入的阶乘小于10位数的时候,我们可以用long long将字符串转化成数字,直接计算. 而当输入的阶乘很大的时候,我们就可以利用位数去大概的估计n. //Asim ...

  2. IDEA之HttpServletRequest之报错解决方案

    @Controller public class UserController { @RequestMapping("/selectUser") public String sel ...

  3. django 上传文件及反馈信息

    from django.shortcuts import render,HttpResponse from django.views import View from Fiskars.models i ...

  4. Navicat使用ssh连接数据库

    1.主机名或ip地址必须填localhost 2.主机名或ip地址必须填外网ip地址

  5. 关于typeid和typeof

    typeid和typeof是c++/gcc编译器的两个关键字,也就是操作符,所以他们根本就不会声明在头文件中. 只不过typeid返回的是type_info,它定义在<typeinfo>头 ...

  6. Python语言知识总结

    1. 环境 1.1 Anaconda 抛弃python原生安装方式吧,使用Anaconda才是最省心的. 1.2 Miniconda Anaconda 太大了,Miniconda才是王道!下载链接:h ...

  7. kaggle竞赛_mnist_10%

      主要是通过mnist了解kaggle的操作细节,最终这里的结果为: 引入必须的库¶ import pandas as pd import numpy as np import matplotlib ...

  8. 集合框架-Map集合

    * Map集合和Collection集合的区别? * Map集合存储元素是成对出现的,Map集合的键是唯一的,值是可重复的.可以把这个理解为:夫妻对 * Collection集合存储元素是单独出现的, ...

  9. Codeforces 581F Zublicanes and Mumocrates - 树形动态规划

    It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The ...

  10. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...