JS获取XML内容!
2008-02-01 23:51
399 查看
XML
<?xml version="1.0" encoding="GB2312"?>
<myfile>
<title>tttt</title>
<author>QinHao</author>
<email>leo-qh@163.com</email>
<date>20080201</date>
</myfile>
JS:
<html>
<head>
<script language="JavaScript" for="window" event="onload">...
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("myfile.xml");
root = xmlDoc.documentElement;
//nodes = xmlDoc.documentElement.childNodes;
document.all("title").innerText = root.childNodes.item(0).text;
document.all("author").innerText = root.childNodes.item(1).text;
document.all("email").innerText = root.childNodes.item(2).text;
document.all("date").innerText = root.childNodes.item(3).text;
</script>
<title>在HTML中调用XML数据</title>
</head>
<body bgcolor="#FFFFFF">
<b>标题: </b>
<span id="title"> </span><br>
<b>作者: </b>
<span id="author"></span><br>
<b>信箱: </b>
<span id="email"></span><br>
<b>日期:</b>
<span id="date"></span><br>
</body>
</html>
<?xml version="1.0" encoding="GB2312"?>
<myfile>
<title>tttt</title>
<author>QinHao</author>
<email>leo-qh@163.com</email>
<date>20080201</date>
</myfile>
JS:
<html>
<head>
<script language="JavaScript" for="window" event="onload">...
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("myfile.xml");
root = xmlDoc.documentElement;
//nodes = xmlDoc.documentElement.childNodes;
document.all("title").innerText = root.childNodes.item(0).text;
document.all("author").innerText = root.childNodes.item(1).text;
document.all("email").innerText = root.childNodes.item(2).text;
document.all("date").innerText = root.childNodes.item(3).text;
</script>
<title>在HTML中调用XML数据</title>
</head>
<body bgcolor="#FFFFFF">
<b>标题: </b>
<span id="title"> </span><br>
<b>作者: </b>
<span id="author"></span><br>
<b>信箱: </b>
<span id="email"></span><br>
<b>日期:</b>
<span id="date"></span><br>
</body>
</html>
相关文章推荐
- JS获取XML内容!
- JS获取XML内容
- Js XMLHTTPRequest 实现GET请求提交和返回内容获取
- JS获取本地文件并且解析文件内容(XML,TXT)
- 利用Asp.net Ajax异步获取xml文档内容
- js获取radio/checkbox内容的的两个例子
- c#修改获取xml中内容
- 百度IFE学习笔记(三)js获取页面内容及后续处理
- 百度IFE学习笔记(三)js获取页面内容及后续处理
- react.js 给标识ref,获取内容
- php获取xml文件内容
- 点击button获取text内容并改变样式的js实现
- js获取超链接的文字内容并放到input中。
- JS获取文本框焦点光标位置、选中起始位置、终止位置、选择内容
- JS获取剪贴板的内容
- JS获取父框架的内容:获取子框架的内容:js框架应用
- js获取UserControl内容,避免拼html的麻烦
- js中获取 table节点各tr及td的内容方法
- js中获取 table节点各tr及td的内容简单实例
- JS与iOS交互之OC获取JS内容跳转到指定控制器实现技巧