zoukankan      html  css  js  c++  java
  • xml 初步学习 读取

    引入xml文件    
    function loadXMLDoc(dname) {         if (window.XMLHttpRequest) {             xhttp = new XMLHttpRequest();         }         else {             xhttp = new ActiveXObject("Microsoft.XMLHTTP");         }         xhttp.open("GET", dname, false);         xhttp.send();         return xhttp.responseXML;     }     xmlDoc = loadXMLDoc("XMLFile1.xml");     document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue + "<br>");     document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue + "<br>");     document.write(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);

    使用text
    function loadXMLString(txt) 
    {
        if (window.DOMParser)
        {
            parser=new DOMParser();
            xmlDoc=parser.parseFromString(txt,"text/xml");
        }
        else 
        {
            // Internet Explorer
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async=false;
            xmlDoc.loadXML(txt); 
        }
        return xmlDoc;
    }
    <script>
    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>";
     
    xmlDoc=loadXMLString(text);
     
    code goes here.....
    </script>


    再三须慎意,第一莫欺心
  • 相关阅读:
    iOS 'The sandbox is not sync with the Podfile.lock错误
    iOS __strong __weak @Strongify @Weakify
    iOS Debug日志 viewhierarchy调试笔记
    网易163 docker镜像
    mysql 双主复制 windows10
    (转) MySQL常用Json函数
    springboot 不同环境读取不同配置
    Mysql Cluster7.5.6 windows10 部署安装
    SourceTree 免登录跳过初始设置
    Java Object to Class
  • 原文地址:https://www.cnblogs.com/otsf/p/8573674.html
Copyright © 2011-2022 走看看