Before learning OC when the XML is too simple, there is no content, the game resources to use the load to find is teacher fooled ~ ~
There are some problems not to be rejected, especially attributes, feel not used first, to be contented often:
Spit trough under W3school, disorderly patchwork, learning like looking for something! Of course, as a free sharing site it is still very great.
Summary from the above (the total feeling missing what):
functionLoadXML (XMLF) {varxmlHttp; varxmldoc; varXmlDom; varXmlele; varStrxml = '<book> <child> <boy> Gaoda </boy> Ailisi <girl> </ girl> </child> <adult> <man> Threebody </man> <woman> Mosh Enxiao </woman> </adult> </book>‘; if(window. XMLHttpRequest) {xmlHttp=NewXMLHttpRequest ();//! IE }Else if(window. ActiveXObject) {xmlHttp=NewActiveXObject (' microsoft.xmlhttp ');//IE } if(xmlhttp!=NULL) {Xmlhttp.onreadystatechange= State_change;//for async True,complete to run,if false not needXmlhttp.open (' GET ', XMLF,false);//GET or Post;xml or ASP or PHP ...; Async true or FalseXmlhttp.send (NULL);//GET null; POST xmldoc } functionState_change () {if(Xmlhttp.readystate = = 4) {//From 0 to 4 if(Xmlhttp.status = = 200) {//Why isn't use &&? //Do somethingXmlDom = Xmlhttp.responsexml;//XML DOMxmldoc = Xmlhttp.responsetext;//XML DocumentXmlele = xmldom.documentelement;//boot Node?}Else{ } } } //parser; XMLHttpRequest for Net,parser? But XMLHttpRequest can load load location also if(Window. Domparser) {//! IE//xmldoc = document.implementation.creatDocument ("', '", null);//WTF//Xmldoc.async = ' false ';//xmldoc.load (XMLF);//var parser = new Domparser ();//xmldoc = parser.parserfromstring (strxml, ' text/xml '); }Else{//IE//xmldoc = new ActiveXObject (' Microsoft.XMLDOM ');//Xmldoc.async = ' false ';//' false '?//xmldoc.load (XMLF);//xml file,get DOM or DOC?//Xmldoc.loadxml (strxml);//xml string } //Not find Firstelementchild/children told by Netbar //node varDom_0 = Xmldom.getelementsbytagname (") [0];//attention S varDom_1 = xmldom.childnodes[1]; varDom_2 =Dom_0.firstchild; varDom_3 =Dom_0.lastchild; varDom_4 =dom_2.nextsibling; varDom_5 =dom_3.previoussibling; varDom_6 = Dom_3.parentnode;//Dom_0 varL_dom = Dom_0.length;//ie<=! ie, #text #conmment in IE would be null and node in! IEdocument.write (dom_0.nodename);//Nodename,read onlydocument.write (Dom_0.nodetype);//nodetype,from 1~9 element:1,read onlydocument.write (Dom_1.childnodes[0].nodevalue);//nodevalue,text in text Node //attribute varattributes = Dom_0.attributes;//Attributes,array varN_att = Attributes.length;//Not real length,real = l+8 (8 format member)document.write (Dom_2.getattribute (‘‘));//getattributeGetAttributeNode (");//difference from getattribute?Dom_2.getnameditem (");//Get attributeRemoveAttribute (‘‘); Removeattributenode (‘‘); WTF Dom_3.setattribute (‘‘,‘‘);//setattribute,if None Creat,none AddAttribute methodXmldom.createattribute (")//Dom_3.setattributenode (");//WTFxmldom.createcdatasection ();//cdata:<! [cdata[Something Data]]>Xmldom.createcomment ();//Note <?--note--? > varNewele = Xmldom.createelement (");//createelement varNewtex = Xmldom.createtextnode (");//createTextNode varNewnod = Dom_3.clonenode (true);//clonenode,true clone node and childnodes,false only node;Newele.appendchild (Newtex);//appendchild to Node (new node)Dom_3.appendchild (Newele);//appendchild to DOM (exist Node), would it change XML?Dom_0.insertbefore (Dom_1,newele);//InsertBeforeDom_0.removechild (dom_2);//RemoveChildDom_0.replacechild (Dom_4);//Replace NodeDom_1.childnodes[0].replacedata (,, ");//position,length,replace text node valueDom_1.childnodes[0].insertdata (, ");//Position,str }
Try after the code inside no Chinese, but also very naïve comment~~~can you understand yourself??
"Learning Notes" XML DOM