如何将xml 转义 成html

如何将xml 转义 成html,第1张

其实html中table本身就是xml格式的,只是现在需要把表格的标签生成到一个纯xml文件

具体实现方法如下:

1、后台办法:

string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + tablename.InnerHtml

2、前台取法:

前台直接使用Jquery更方便

var xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +$("tablename").html()

表格代码如下

[code=html] <table id="tablename" runat="server" >

<tr>

<td></td>

</tr>

</table>[/code]

后台需要加上这两个 id="tablename" runat="server"

先把你要转换的文件放到我的电脑!就我的文档C吧(比如)。然后点文档C,再点“文件夹”上的“工具”。点“文件夹选项(O)”再点上面的“查看”然后点“隐藏受保护的 *** 作系统文件”最后把你要换的文件名称最后的字不是格式吗(HTML,什么的)把原先删掉,换成你要的比如XML就行了,不过不是每个文件都适合任何格式的

可以通过xslt来实现 。

XSLT(Extensible StyleSheet Language Transmations),是XSL(可扩展样式语言)的一种,是一种基于模版的样式转换语言,说的直接一点就是可以把XML文本转成其他格式的文本,那么一起来看转换的代码:

[html] view plain copy print?

<?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>

<head>

<title>Review of My Dogs</title>

</head>

<body>

<h4>list of My Dogs</h4>

<table width="100%" border="1">

<thead>

<tr>

<th>Name</th>

<th>Breed</th>

<th>Age</th>

<th>Full Blood</th>

<th>Color</th>

</tr>

</thead>

<tbody>

<xsl:apply-templates/>

</tbody>

</table>

</body>

</html>

</xsl:template>

<xsl:template match="dog">

<tr>

<td>

<strong><xsl:value-of select="name" /></strong>

</td>

<td><xsl:value-of select="@breed" /></td>

<td><xsl:apply-templates select="age" /></td>

<td><xsl:value-of select="fullBlood" /></td>

<td><xsl:value-of select="color" /></td>

</tr>

</xsl:template>

<xsl:template match="age">

<xsl:value-of select="years" />years

<xsl:value-of select="months" />months

</xsl:template>

</xsl:stylesheet>

将上面的代码写在记事本里,保存成xsl格式,然后再XML文档中引入:

[html] view plain copy print?

<?xml version="1.0" encoding="iso-8859-1"?>

<?xml-stylesheet type="text/xsl" href="mydogs.xsl"?>

<myDogs>

<dog breed="labrador">

<name>morgan</name>

<age>

<years>1</years>

<months>10</months>

</age>

<fullBlood>yes</fullBlood>

<color>Chocolate</color>

</dog>

</myDogs>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7310111.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存