XML 树
<bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> |
有于有不同的浏览器,所以对XML DOM有所不同,主流的就是Microsfot IE跟FIREFOX,还有OPERA,等等,
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); //定义一个基于Microsoft.XMLDOM的空对象,有于不同的的浏览器而定 xmlDoc.async="false"; //The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded. xmlDoc.load("note.xml");//截入XML文件 var parser=new DOMParser(); //定义一个XML DOCUMENT对象 var doc=parser.parseFromString(txt,"text/xml"); 把xml文件转为string |