建立MS XML 測試環(huán)境_Xml教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:javascript調用XML制作連動下拉框
      傳統(tǒng)的HTML頁面中連動下拉框采用了兩種方法: 1)直接將下拉框中的內容hardcode于html的javascript中,調用javascript函數循環(huán)寫入下拉框中。這種方法不適用于下拉框內容經常改變的情況。因

      一般的Windows環(huán)境(Windows 98 SE以上版本)都有一個MSXML環(huán)境,以下的asp代碼可以運行,但不一定工作,不工作可能是由于樣式單是http://www.w3.org/1999/XSL/Transform的,而最初環(huán)境只支持http://www.w3.org/TR/WD-xsl,所以可能什么也不出來。

      以下為引用的內容:

      <%@ LANGUAGE = JScript %>
      <%
      // Set the source and style sheet locations here
      var sourceFile = Server.MapPath("test.xml");
      var styleFile = Server.MapPath("test.xsl");

      // Load the XML
      var source = Server.CreateObject("Microsoft.XMLDOM");
      source.async = false;
      source.load(sourceFile);
      // Load the XSL
      var style = Server.CreateObject("Microsoft.XMLDOM");
      style.async = false;
      style.load(styleFile);
      Response.Write(source.transformNode(style));
      %>

      一般以MSXML為開發(fā)環(huán)境的都要建立安裝新的解析器,如MSXML 3或者MSXML 4 Technology Preview,在以replace方式裝了MSXML 3后,我們可以使用以下的代碼

      以下為引用的內容:

      <%@ LANGUAGE = JScript %>
      <%
      // Set the source and style sheet locations here
      var sourceFile = Server.MapPath("test.xml");
      var styleFile = Server.MapPath("test.xsl");

      // Load the XML
      var source = Server.CreateObject("Msxml2.DOMDocument");
      source.async = false;
      source.load(sourceFile);
      // Load the XSL
      var style = Server.CreateObject("Msxml2.DOMDocument");
      style.async = false;
      style.load(styleFile);
      Response.Write(source.transformNode(style));
      %>

      這樣我們獲得了MSXML 3的開發(fā)環(huán)境,但如果我們不想破壞原來的環(huán)境,又要測試我們基于MSXML 3的例子呢,雖然用replace方式安裝提供了向后兼容方式來支持XSL元素,函數和XSL命名空間。

      其實使用版本無關progIDs(version-dependent progIDs)來創(chuàng)建對象實例可以更好的完成工作,我們不需要用replace方式安裝,用side-by-side方式即可,我們看下面的代碼:

      以下為引用的內容:

      <%@ LANGUAGE = JScript %>
      <%
      // Set the source and style sheet locations here
      var sourceFile = Server.MapPath("test.xml");
      var styleFile = Server.MapPath("test.xsl");

      // Load the XML
      var source = Server.CreateObject("Msxml2.DOMDocument.3.0");
      source.async = false;
      source.load(sourceFile);
      // Load the XSL
      var style = Server.CreateObject("Msxml2.DOMDocument.3.0");
      style.async = false;
      style.load(styleFile);
      Response.Write(source.transformNode(style));
      %>

      只需要在Msxml2.DOMDocument后面加上版本號3.0,即可使用MSXML 3的東東了,MSXML 4呢,依次類推。

      在客戶端的環(huán)境也是一樣的,用js創(chuàng)建DOM對象是一樣的。

      以下為引用的內容:
      function test(){
      var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
      var currNode;
      xmlDoc.async = false;
      xmlDoc.load("test.xml");
      currNode = xmlDoc.documentElement.firstChild;
      alert(currNode.xml);
      }

      最后,XSLT樣式單side-by-side方式下在Internet Explorer 5.0及以后版本不支持。如果你要使用IE 5來打開XSLT樣式單,需要用replace方式安裝.

      分享:快速通過XSL轉換XML文件
      XML可以只注重數據與文件格式的描述,而顯示方面的工作就交給排版樣式表。排版樣式表分:CSS和XSL。其中XSL非常適合XML。   最近,我喜歡上了XML編程,但又苦于它的美觀程度又

      來源:模板無憂//所屬分類:Xml教程/更新時間:2008-08-22
      相關Xml教程