如何把 XML 数据显示为 HTML(加载XML/XSL几种方式)
2010-08-11 09:05
627 查看
加载XSL和XML通常有几种方式:
1、 客户端加载(javascript)
<html>
<body>
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{
// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{
// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("cd_catalog.xml");
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
</body>
</html>
2、 服务器端加载(Asp.net)
<%@ Control Language="c#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<script runat="server" language="c#">
public string xmlSource, xslSource;
void Page_Load(){
XmlDocument docXml = new XmlDocument();
docXml.Load(Server.MapPath(xmlSource));
XslTransform docXsl = new XslTransform();
docXsl.Load(Server.MapPath(xslSource));
docXsl.Transform(docXml,null,Response.Output);
// chapter.Text = docXml.TransformNode(docXsl);
}
</script>
1、 客户端加载(javascript)
<html>
<body>
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{
// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{
// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("cd_catalog.xml");
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
</body>
</html>
2、 服务器端加载(Asp.net)
<%@ Control Language="c#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<script runat="server" language="c#">
public string xmlSource, xslSource;
void Page_Load(){
XmlDocument docXml = new XmlDocument();
docXml.Load(Server.MapPath(xmlSource));
XslTransform docXsl = new XslTransform();
docXsl.Load(Server.MapPath(xslSource));
docXsl.Transform(docXml,null,Response.Output);
// chapter.Text = docXml.TransformNode(docXsl);
}
</script>
相关文章推荐
- 如何读取xml数据并显示在html页面
- 用js如何实现读取xml数据并且显示在html中
- 查看如何在一个 HTML 表格中显示 XML 数据。
- 异步加载封装结果为xml数据,xsl文件解析xml数据显示在指定的div中
- Spring加载applicationContext.xml的几种方式
- 通过xsl显示和输出XML数据
- XML+XSL在表格中显示数据的主要程序
- ExtJS4加载FormPanel数据的几种方式
- Visual C# 2005 - 如何于DataGridView控件中以跨数据行方式显示数据
- C#中如何将XML+XSL文档转换为HTML格式
- EF如何操作内存中的数据以及加载相关联表的数据:延迟加载、贪婪加载、显示加载
- Spring加载上下文几种方式(Spring配置XML)
- 利用XSL对XML中的数据进行数据显示之一
- 通过xsl显示和输出XML数据2
- 如何用TextView显示Html格式的数据
- Visual C# 2005 - 如何于DataGridView控件中以跨数据行方式显示数据
- XML基础知识学习八(使用XSL来显示XML数据)
- 总结ASP.NET MVC Web Application中将数据显示到View中的几种方式
- 如何从数据库调出数据显示到页面 PHP+Mysql+Html
- webView显示html到Js调用手机功能到Base64的方式将数据返回到Html中