<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-314  評論-209  文章-0  trackbacks-0
    本文摘自http://www.w3schools.com,雖是英文版,但其腳本用法相信大家還是看得懂的,希望對大家編寫基于xml的網(wǎng)頁有所幫助。

    To read and update - create and manipulate - an XML document, you will need an XML parser.


    Microsoft's XML Parser

    Microsoft's XML parser is a COM component that comes with Internet Explorer 5 and higher. Once you have installed Internet Explorer, the parser is available to scripts.

    Microsoft's XML parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.

    The following table lists the most commonly used node types supported by Microsoft's XML parser:

    Node TypeExample
    Processing instruction<?xml version="1.0"?>
    Element<drink type="beer">Carlsberg</drink>
    Attributetype="beer"
    TextCarlsberg

    MSXML Parser 2.5 is the XML parser that is shipped with Windows 2000 and IE 5.5.

    MSXML Parser 3.0 is the XML parser that is shipped with IE 6.0 and Windows XP.

    The MSXML 3.0 parser features:

    • JavaScript, VBScript, Perl, VB, Java, C++, etc. support
    • Complete XML support
    • Full DOM and Namespace support
    • DTD and validation
    • Complete XSLT and XPath support
    • SAX2 support
    • Server-safe HTTP

    To create an instance of Microsoft's XML parser with JavaScript, use the following code:

    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")

    To create an instance of Microsoft's XML parser with VBScript, use the following code:

    set xmlDoc=CreateObject("Microsoft.XMLDOM")

    To create an instance of Microsoft's XML parser in an ASP page (using VBScript), use the following code:

    set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")

    The following code loads an existing XML document ("note.xml") into Microsoft's XML parser:

    <script type="text/javascript">
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
    xmlDoc.async="false"
    xmlDoc.load("note.xml")
    ...
    ...
    ...
    </script>

    The first line of the script above creates an instance of the Microsoft XML parser. The third line tells the parser to load an XML document called "note.xml". The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.


    XML Parser in Mozilla Browsers

    Plain XML documents are displayed in a tree-like structure in Mozilla (just like IE).

    Mozilla also supports parsing of XML data using JavaScript. The parsed data can be displayed as HTML.

    To create an instance of the XML parser with JavaScript in Mozilla browsers, use the following code:

    var xmlDoc=document.implementation.createDocument("ns","root",null)

    The first parameter, ns, defines the namespace used for the XML document. The second parameter, root, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.

    The following code loads an existing XML document ("note.xml") into Mozillas' XML parser:

    <script type="text/javascript">
    var xmlDoc=document.implementation.createDocument("","",null);
    xmlDoc.load("note.xml");
    ...
    ...
    ...
    </script>

    The first line of the script above creates an instance of the XML parser. The second line tells the parser to load an XML document called "note.xml".


    Loading an XML File - A Cross browser Example

    The following example is a cross browser example that loads an existing XML document ("note.xml") into the XML parser:

    <html>
    <head>
    <script type="text/javascript">
    var xmlDoc
    function loadXML()
    {
    //load xml file
    // code for IE
    if (window.ActiveXObject)
      {
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.load("note.xml");
      getmessage()
      }
    // code for Mozilla, etc.
    else if (document.implementation &&
    document.implementation.createDocument)
      {
      xmlDoc= document.implementation.createDocument("","",null);
      xmlDoc.load("note.xml");
      xmlDoc.onload=getmessage
      }
    else
      {
      alert('Your browser cannot handle this script');
      }
    }
    function getmessage()
    {
    document.getElementById("to").innerHTML=
    xmlDoc.getElementsByTagName("to")[0].firstChild.nodeValue
    document.getElementById("from").innerHTML=
    xmlDoc.getElementsByTagName("from")[0].firstChild.nodeValue
    document.getElementById("message").innerHTML=
    xmlDoc.getElementsByTagName("body")[0].firstChild.nodeValue
    }
    </script>
    </head>
    <body onload="loadXML()" bgcolor="yellow">
    <h1>W3Schools Internal Note</h1>
    <p><b>To:</b> <span id="to"></span><br />
    <b>From:</b> <span id="from"></span>
    <hr />
    <b>Message:</b> <span id="message"></span>
    </p>
    </body>
    </html>

    Try it yourself


    Loading XML Text Into the Parser

    Internet Explorer supports two ways of loading XML into a document object: the load() method and the loadXML() method. The load() method loads an XML file and the loadXML() method loads a text string that contains XML code.

    The following code loads a text string into Microsoft's XML parser:

    <script type="text/javascript">
    var txt="<note>"
    txt=txt+"<to>Tove</to><from>Jani</from>"
    txt=txt+"<heading>Reminder</heading>"
    txt=txt+"<body>Don't forget me this weekend!</body>"
    txt=txt+"</note>"
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
    xmlDoc.async="false"
    xmlDoc.loadXML(txt)
    ...
    ...
    ...
    </script>

    If you have Internet Explorer, you can try it yourself.

    posted on 2006-11-16 12:20 xzc 閱讀(2245) 評論(1)  編輯  收藏 所屬分類: XML

    評論:
    # re: 兼容在IE和Firefox瀏覽器下操作XML(英)[未登錄] 2008-10-26 23:11 | yy
    很實用,感謝!!!  回復(fù)  更多評論
      
    主站蜘蛛池模板: 成人在线免费观看| 东方aⅴ免费观看久久av| 亚州免费一级毛片| 亚洲日本va午夜中文字幕一区| 中文在线观看免费网站| 亚洲小说区图片区另类春色| 色吊丝性永久免费看码| 亚洲美女高清一区二区三区| 麻豆安全免费网址入口| 免费一级毛片在线播放不收费| 日韩亚洲人成在线综合| 亚洲成?Ⅴ人在线观看无码| 日韩精品视频在线观看免费| 亚洲熟伦熟女新五十路熟妇 | 无人视频在线观看免费播放影院| yy6080亚洲一级理论| 免费夜色污私人影院网站电影| 久久久久亚洲AV无码专区网站| 精选影视免费在线 | 亚洲日本精品一区二区| 成年女人免费v片| 曰批全过程免费视频免费看| 亚洲国产一区视频| 国内精品一级毛片免费看| 亚洲欧洲国产成人精品| 成人无遮挡裸免费视频在线观看| 最新亚洲人成无码网站| 国产精品亚洲片在线| 青草草色A免费观看在线| 亚洲AV无码成人精品区日韩| 亚洲综合色婷婷七月丁香| 国产白丝无码免费视频| 亚洲熟妇自偷自拍另欧美| 亚洲日韩精品无码专区网站| 99国产精品免费视频观看| 亚洲成av人无码亚洲成av人| 亚洲色精品aⅴ一区区三区| 67194熟妇在线永久免费观看| 日本系列1页亚洲系列| 97亚洲熟妇自偷自拍另类图片| 欧美三级在线电影免费|