js 加載并解析XML字符串的代碼
更新時(shí)間:2009年12月13日 00:40:40 作者:
js 加載并解析XML字符串的實(shí)現(xiàn)代碼,需要的朋友可以參考下。
JS加載xml文檔實(shí)例
books.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="children">
<title lang="en">chabaoo.cn</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>
loadxml.htm
<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>
下面的是加載與解析xml文件的例子,但xml是自定義的字符串,一般在后臺(tái)語(yǔ)言中用的到。
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
如果看完了上面的實(shí)例可以看下下面的文章。
http://chabaoo.cn/article/14604.htm
books.xml
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="children">
<title lang="en">chabaoo.cn</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>
loadxml.htm
復(fù)制代碼 代碼如下:
<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>
下面的是加載與解析xml文件的例子,但xml是自定義的字符串,一般在后臺(tái)語(yǔ)言中用的到。
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
如果看完了上面的實(shí)例可以看下下面的文章。
http://chabaoo.cn/article/14604.htm
您可能感興趣的文章:
相關(guān)文章
JavaScript學(xué)習(xí)筆記之?dāng)?shù)組基本操作示例
這篇文章主要介紹了JavaScrip學(xué)習(xí)筆記之?dāng)?shù)組基本操作,結(jié)合實(shí)例形式分析了javascript數(shù)組的基本定義、添加、刪除、修改、連接、排序等操作技巧,需要的朋友可以參考下2019-01-01DataTables添加額外的查詢(xún)參數(shù)和刪除columns等無(wú)用參數(shù)實(shí)例
下面小編就為大家?guī)?lái)一篇DataTables添加額外的查詢(xún)參數(shù)和刪除columns等無(wú)用參數(shù)實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07javascript簡(jiǎn)單實(shí)現(xiàn)跟隨滾動(dòng)條漂浮的返回頂部按鈕效果
這篇文章主要介紹了javascript簡(jiǎn)單實(shí)現(xiàn)跟隨滾動(dòng)條漂浮的返回頂部按鈕效果,涉及javascript基于onscroll事件動(dòng)態(tài)改變頁(yè)面元素樣式的相關(guān)技巧,需要的朋友可以參考下2016-08-08JS簡(jiǎn)單實(shí)現(xiàn)點(diǎn)擊按鈕或文字顯示遮罩層的方法
這篇文章主要介紹了JS簡(jiǎn)單實(shí)現(xiàn)點(diǎn)擊按鈕或文字顯示遮罩層的方法,涉及javascript鼠標(biāo)事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-04-04JavaScript自定義等待wait函數(shù)實(shí)例分析
這篇文章主要介紹了JavaScript自定義等待wait函數(shù),實(shí)例分析了自定義等待函數(shù)的實(shí)現(xiàn)與使用技巧,需要的朋友可以參考下2015-03-03