JS加载xml文档
2009-12-12 14:43
232 查看
WWW.U8686.COM-信息发布平台
JS加载xml文档
<html>
<head>
<script>
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)}
}
try
{
xmlDoc.async=false;
xmlDoc.load("books.xml");
document.write(xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue);
}
catch(e){alert(e.message);}
</script>
</head>
<body>
</body>
</html>
books.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Copyright w3school.com.cn -->
<!-- W3School.com.cn bookstore example -->
<bookstore>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
</bookstore>
JS加载xml文档
<html>
<head>
<script>
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)}
}
try
{
xmlDoc.async=false;
xmlDoc.load("books.xml");
document.write(xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue);
}
catch(e){alert(e.message);}
</script>
</head>
<body>
</body>
</html>
books.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Copyright w3school.com.cn -->
<!-- W3School.com.cn bookstore example -->
<bookstore>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
</bookstore>
相关文章推荐
- XLoadTree 基于AJAX + XML动态加载的JS树组件的文档翻译
- js解析xml文档设置 同步/异步加载
- 加载xml文档(原生JS版及jQuery版)
- C# 加载xml文档文件及加载xml字符串
- Js读取xml,加载到页面
- js xml文件加载
- AS3.0加载XML出现“#1088 文档中根元素后面的标记格式必须正确”的解决方法
- pom.xml文件显示错误 或 sockjs.min.js文件加载错误
- 使用SimpleXML函数来加载和解析XML文档
- 使用Linq to XML加载XML文档
- 在HTML中通过JS实现对XML的加载
- XML 文档对象模型----加载和使用XmlDocument (w3c DOM)
- Google Maps API 进级:通过XML文档加载Gpolyline或者Gpolygon
- 保存和加载XML文档
- 文档加载完毕执行JS的三种方法
- js读取xml文档,并实现简单分页
- 使用 js 处理XML 文档
- microsoft.xmldom(一) xml文档遍历js
- JS实现文档加载完成后执行代码
- js加载新文档