灵活调用xsl来解析xml文档
1.新建一个vs2003的web工程,取名为XMLTest<BR><BR> 2.将工程目录下的WebForm1.aspx中内容全部删除,只留下顶部的一条语句:<BR><BR> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="XMLTest.WebForm1" %><BR><BR><BR>3.修改WebForm1.aspx.cs中内容,在Page_Load中加入:<BR><BR>XmlDocument doc=new XmlDocument(); <BR> String xmlfile=string.Empty; <BR> xmlfile=Context.Request.PhysicalApplicationPath (Request.QueryString["sel"].ToString()=="xml"?"\\hello.xml":"\\hello.xsl"); <BR> doc.Load(xmlfile); <BR> Response.Write(doc.InnerXml);<BR><BR> 4.在工程根目录下新增test.htm,并设为工程首页:<BR><BR>
<html> <BR><head> <BR><title></title> <BR></head> <BR><body> <BR><div id="resTree"></div> <BR><FONT face="宋体"></FONT><input type="button" value="执行" onclick="GetXml()"><BR> <BR><script language="JScript"> <BR>var srcTree,xsltTree,xt; <BR>var http_request = false; <BR> <BR>function GetXml() <BR>{ <BR> srcTree = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); <BR> srcTree.async=false; <BR> xsltTree= new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); <BR> xsltTree.async = false; <BR> xt=new ActiveXObject("MSXML2.XSLTemplate"); <BR> resTree.innerHTML=""; <BR> makeRequest("WebForm1.aspx?sel=xml",GetXml_CB); <BR>} <BR> <BR> function makeRequest(url,callback) { <BR> http_request = false; <BR> if (window.XMLHttpRequest) { // Mozilla, Safari,... <BR> http_request = new XMLHttpRequest(); <BR> if (http_request.overrideMimeType) { <BR> http_request.overrideMimeType('text/xml'); <BR> } <BR> } else if (window.ActiveXObject) { // IE <BR> try { <BR> http_request = new ActiveXObject("Msxml2.XMLHTTP"); <BR> } catch (e) { <BR> try { <BR> http_request = new ActiveXObject("Microsoft.XMLHTTP"); <BR> } catch (e) {} <BR> } <BR> } <BR><BR> if (!http_request) { <BR> alert('Giving up :( Cannot create an XMLHTTP instance'); <BR>
页:
[1]