Home > Web Front-end > JS Tutorial > js code to load and parse XML string_javascript skills

js code to load and parse XML string_javascript skills

WBOY
Release: 2016-05-16 18:39:38
Original
965 people have browsed it

JS加载xml文档实例
books.xml

复制代码 代码如下:




www.jb51.net
J K. Rowling
2005
29.99


Everyday Italian
Giada De Laurentiis
2005
30.00


Learning XML
Erik T. Ray
2003
39.95


XQuery Kick Start
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
2003
49.99




loadxml.htm
复制代码 代码如下:



<script> <br>try //Internet Explorer <br>{ <br>xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); <br>} <br>catch(e) <br>{ <br>try //Firefox, Mozilla, Opera, etc. <br>{ <br>xmlDoc=document.implementation.createDocument("","",null); <br>} <br>catch(e) {alert(e.message)} <br>} <br>try <br>{ <br>xmlDoc.async=false; <br>xmlDoc.load("books.xml"); <br>document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue); } <br>catch(e){alert(e.message);} <br></script>





下面的是加载与解析xml文件的例子,但xml是自定义的字符串,一般在后台语言中用的到。

[Ctrl A 全选 注:如需引入外部Js需刷新才能执行
]

如果看完了上面的实例可以看下下面的文章。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template