js解析 XML 字符串
js解析 XML 字符串 - 跨浏览器实例<html><body><script type="text/javascript">text="<bookstore>"text=text+"<book>";text=text+"<title>Everyday Italian</title>";text=text+"<author>Giada De Laurentiis</author>";text=text+"<year>2005</year>";text=text+"</book>";text=text+"</bookstore>";try //Internet Explorer{xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(text);}catch(e){try //Firefox, Mozilla, Opera, etc. { parser=new DOMParser(); xmlDoc=parser.parseFromString(text,"text/xml"); }catch(e) {alert(e.message)}}try {document.write(xmlDoc.getElementsByTagName("title").childNodes.nodeValue);document.write("<br />");document.write(xmlDoc.getElementsByTagName("author").childNodes.nodeValue);document.write("<br />");document.write(xmlDoc.getElementsByTagName("year").childNodes.nodeValue);}catch(e) {alert(e.message)}</script></body></html>输出:Everyday ItalianGiada De Laurentiis2005
页:
[1]