zoukankan      html  css  js  c++  java
  • XML

    xpath 路径表达式 为XSL提供路径

    XSL = XML 样式表

    XML Dom 操作xml 元素

    XML 所展示的页面-> XHTML

    获取XML:

    1> 字符串转化为xml

    txt="<note>";
    txt=txt+"<to>George</to>";
    txt=txt+"<from>John</from>";
    txt=txt+"<heading>Reminder</heading>";
    txt=txt+"<body>Don't forget the meeting!</body>";
    txt=txt+"</note>";
    
    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);
      }

    2> 获得xml文件

    var xmlhttp;
    if
    (window.XMLHttpRequest) {// all modern browsers xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) {// for IE5, IE6 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
    if(xmlhttp!=null)
      {
    //xmlhttp.onreadystatechange=state_Change;
    xmlhttp.open("GET","/example/xmle/cd_catalog.xml",false);
    xmlhttp.send();//或者 xmlhttp.send(null) xmlDoc=xmlhttp.responseXML;

      }
    else
      {
      alert("Your browser does not support XMLHTTP.");
      }
    function state_Change(){
    if(xmlhttp.readyState!=4) return;
    if(xmlhttp.status!=200) return;
    //xmlhttp.getResponseHeader('Last-Modified');
    //xmlhttp.getAllResponseHeaders();
    // xmlhttp.responseXML.documentElement.getElementsByTagName("CD") 在这里用这个 并改为true

    }

    解析XML:

    1>XML Dom 操作 对象"CD"

    var x=xmlDoc.getElementsByTagName("CD");
    document.write("<table border='1'>");

    2>XML Dom 获得对象文本

    document.getElementById("from").innerHTML=
    xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;

    命名空间:避免命名空间冲突

    1>字母+:

    <h:table xmlns:h="http://www.w3.org/TR/html4/">
       <h:tr>
       <h:td>Apples</h:td>
       <h:td>Bananas</h:td>
       </h:tr>
    </h:table> 

    2>namespace-prefix=赋值

    xmlns:namespace-prefix="namespaceURI" 

    3>xmlns=赋值

    <table xmlns="http://www.w3school.com.cn/furniture">
       <name>African Coffee Table</name>
       <width>80</width>
       <length>120</length>
    </table>

    实际空间命名应用:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
    <html>
    <body>
      <h2>My CD Collection</h2>
      <table border="1">
        <tr>
          <th align="left">Title</th>
          <th align="left">Artist</th>
        </tr>
        <xsl:for-each select="catalog/cd">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
        </tr>
        </xsl:for-each>
      </table>
    </body>
    </html>
    </xsl:template>
    
    </xsl:stylesheet>

    预定义必用:

    &lt;     <     小于
    &gt;     >     大于
    &amp;     &     和号
    &apos;     '     省略号
    &quot;     "     引号

    CDATA:解析器忽略标签

    <![CDATA[" 开始,由 "

    ]]>

    服务器加载XML:

    set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load(Server.MapPath("simple.xml"))

    保存成XML:

    text=text & "</note>"
    
    set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
    xmlDoc.async="false"
    xmlDoc.loadXML(text)
    
    xmlDoc.Save("test.xml")

    XML Dom 操作:

    txt=xmlDoc.getElementsByTagName("title")[0].getAttribute("lang");
    .setAttribute("edition","first");
    newel=xmlDoc.createElement("edition");
    newtext=xmlDoc.createTextNode("First");
    newel.appendChild(newtext);
    
    x=xmlDoc.getElementsByTagName("book");
    x[0].appendChild(newel);
    .removeChild(x.childNodes[0]);
  • 相关阅读:
    【bzoj3083】遥远的国度 树链剖分+线段树
    【bzoj2226】[Spoj 5971] LCMSum 欧拉函数
    xml、json的序列化与反序列化
    什么是安全证书,访问者到底是怎么校验安全证书的,服务端返回安全证书后,客户端再向谁验证呢?
    查看发票组代码后的总结和有感
    网址的正则表达式、常用正则表达式、在线正则表达式检测
    XamlParseException异常
    委托,lambda,匿名方法
    windows中断与共享的连接(samba)
    linux ubuntu 11.04 samba 服务器设置
  • 原文地址:https://www.cnblogs.com/woloveprogram/p/5145587.html
Copyright © 2011-2022 走看看