zoukankan      html  css  js  c++  java
  • 【学习笔记】 XML DOM

    以前学OC的时候觉得XML太简单了没什么内容,游戏资源加载要用到发现是被teacher忽悠了~~

    还有一些没决绝的问题,特别是attributes,感觉不常用就先撂着,要知足常撂:)

    吐槽下w3school,乱七八糟东拼西凑的,学习像在找东西!当然作为免费分享站点它还是很伟大的。

    从上面找到的总结(总感觉漏了什么):

    function loadXML(xmlf){
        var xmlHttp;
        var xmlDoc;
        var xmlDom;
        var xmlEle;
        var strXML = '<book>
                        <child>
                            <boy>
                            gaoda
                            </boy>
                            ailisi
                            <girl>
                            </girl>
                        </child>
                        <adult>
                            <man>
                            threebody
                            </man>
                            <woman>
                            moshenxiao
                            </woman>
                        </adult>
                      </book>';
        if(window.XMLHttpRequest){
            xmlHttp = new XMLHttpRequest();//!IE
    
        }else if(window.ActiveXObject){
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');//IE
        }
    
        if(xmlHttp!=null){
            xmlHttp.onreadystatechange = state_Change;//for async true,complete to run,if false not need 
            xmlHttp.open('GET',xmlf,false);//GET or POST;xml or asp or PHP...;Async true or false
            xmlHttp.send(null);//GET null;POST xmlDoc
        }
        
        function state_Change(){
            if(xmlHttp.readyState == 4){//from 0 to 4
                if(xmlHttp.status == 200){//why not use &&?
                    //do something
                    xmlDom = xmlHttp.responseXML;//XML DOM
                    xmlDoc = xmlHttp.responseText;//XML Document
                    xmlEle = xmlDom.documentElement;//boot Node?
                }else{
    
                }
            }
        }
    
        //parser; XMLHttpRequest for net,parser for location?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
        var dom_0 = xmlDom.getElementsByTagName('')[0];//attention s
        var dom_1 = xmlDom.childNodes[1];
        var dom_2 = dom_0.firstChild;
        var dom_3 = dom_0.lastChild;
        var dom_4 = dom_2.nextSibling;
        var dom_5 = dom_3.previousSibling;
        var dom_6 = dom_3.parentNode;//dom_0
    
        var l_dom = dom_0.length;//IE<=!IE,#text #conmment in IE will be null but node in !IE
    
        document.write(dom_0.nodeName);//nodeName,read only
        document.write(dom_0.nodeType);//nodeType,from 1~9 element:1,read only
        document.write(dom_1.childNodes[0].nodeValue);//nodeValue,text in text Node
        //attribute
        var attributes = dom_0.attributes;//attributes,array
        var n_att = attributes.length;//not real length,real = l+8(8 format member)
    
        document.write(dom_2.getAttribute(''));//getAttribute
        getAttributeNode('');//difference from getAttribute?
        dom_2.getNamedItem('');//get attribute
    
        removeAttribute('');
        removeAttributeNode('');WTF
        
    
        dom_3.setAttribute('','');//setAttribute,if none creat,none addAttribute method
        xmlDom.createAttribute('')//
        dom_3.setAttributeNode('');//WTF
    
        xmlDom.createCDATAsection();//CDATA:<![CDATA[ something data ]]>
        xmlDom.createComment();//note <?--note--?>
    
        var newEle = xmlDom.createElement('');//createElement
        var newTex = xmlDom.createTextNode('');//createTextNode
        var newNod = 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);//insertBefore
        dom_0.removeChild(dom_2);//removeChild
        dom_0.replaceChild(dom_4);//replace Node
        dom_1.childNodes[0].replaceData(,,'');//position,length,replace text node value
        dom_1.childNodes[0].insertData(,'');//position,str
         
    }
    //E4X so easy
    ver xmlDoc =new XML();//xmlDoc =new XML(strXML);
    xmlDoc.load(file.xml);

    AJAX待补充~~

    尝试下以后代码里面不用chinese了,还很幼稚的comment~~~Can you understand yourself??

  • 相关阅读:
    CentOS6.9下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数
    Debian9.5下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数
    CentOS6.9下sftp配置和scp用法
    Debian9.5下sftp配置和scp用法
    SSH概述与配置文件说明
    Linux下的权限掩码umask
    gcc 高版本兼容低版本 技巧 :指定 -specs={自定义specs文件} 参数。可以搞定oracle安装问题
    apt 之 最强技能:【欺骗】,文雅点【偷梁换柱】!
    续:纠正:ubuntu 【6.04 LTS】可以安装安装 ! for《Oracle-10.2.0.1,打补丁10.2.0.5:在 debian 版本4【不含4】以上,及 ubuntu 7.04【不含7.04】以上都可以安装!》
    ubuntu 4.10~5.10 :古老的ubuntu上安装oracle10g的情况
  • 原文地址:https://www.cnblogs.com/flytu/p/4373907.html
Copyright © 2011-2022 走看看