创建一个空的XML文档:
var XML={}; XML.newDocument=function(rootTagname,namespaceURL){ if(!rootTagname) rootTagname=""; if(!namespaceURL) namespaceURL=""; if(document.implementation && document.implementation.createDocument){ //This is the W3C standard way to do it return document.implementation.createDocument(namespaceURL,rootTagname,null); } else{ //This is the IE way to do it //Create an empty document as an ActiveX object var doc=new ActiveXObject("MSXML2.DOMDocument"); if(rootTagname){ var prefix=""; var tagname=rootTagname; var p=rootTagname.indexOf(':'); if(p!=-1){ prefix=rootTagname.substring(0,p); tagname=rootTagname.substring(p+1); } //If we have a namespace,we must have a namespace prefix //If we don,t have a namespace,we discard any prefix if(namespaceURL){ if(!prefix) prefix="a0"; //what firefox uses } else{ prefix=""; } //Create the root element as a string of text var text="<"+(prefix?(prefix+":"):"")+tagname+ (namespaceURL?("xmlns:"+prefix+'="'+namespaceURL+'"'):"") +"/>"; //And prase that text into the empty document doc.loadXML(text); } return doc; } };
从xml中提取信息
address.xml:
able@example.com dodger@example.com frame@example.com
HTML: