XML CDATA HTML里面正在转换与和放大器; LT;和&安培; GT;括号 [英] HTML inside XML CDATA being converted with < and > brackets
问题描述
我有一些示例XML:
<样品><![CDATA [1线474; BR /> 2线474; BR />线路3'; BR />]]>< /样品>
我使用ASP输出使用样式表像这样这个XML:
设置XMLHTTP =的Server.CreateObject(Microsoft.XMLHTTP)
xmlHttp.openGET,URLxml,假
xmlHttp.send()设置xslHttp =的Server.CreateObject(Microsoft.XMLHTTP)
xslHttp.openGET,xXsl,假
xslHttp.send()设置xmlDoc中=的Server.CreateObject(MICROSOFT.XMLDOM)
设置名为xsldoc =的Server.CreateObject(MICROSOFT.XMLDOM)
xmlDoc.async = FALSE
xslDoc.async = FALSE
xmlDoc.Load xmlHttp.responseXML
xslDoc.Load xslHttp.responseXML回复于xmlDoc.transformNode(名为xsldoc)
不过,这一次是越来越写的,HTML输出显示为:
1安培线; LT; BR /&放大器; GT; 2号线和放大器; LT; BR /&放大器; GT; 3号线
我可以看到,ASP是转换括号中的code,但我不知道为什么。有什么想法?
我有一些示例XML:
<样品><![CDATA [1线474; BR /> 2线474; BR />线路3'; BR />]]>< /样品>
块引用>这是一个
样品
与文本节点元素孩子假设你申请一个身份转换。那么结果将是:
<样品→1号线和放大器; LT; BR /&放大器; GT; 2号线和放大器; LT; BR /&放大器; GT; 3号线和放大器; LT; BR /&放大器; GT;&LT ; /样品>
为什么呢?由于文本节点和属性值有特殊字符
&安培;
,<
和>
逸出字符实体。修改:当然,你可以使用DOE ......但是,除了它是一个可选功能后,其结果将是一个文本节点不管什么(不带连接code字符实体)。您将需要其他的解析器抽油机(这可能是有用的,当输出和连接code HTML片段到(X)HTML文档就像在饲料,与产量畸形的危险......)。
这个样式表:
<的xsl:样式版本=1.0的xmlns:XSL =http://www.w3.org/1999/XSL/Transform>
<的xsl:模板匹配=样品>
&所述p为H.;
<的xsl:value-of的选择=。禁用输出转义=是/>
&所述; / P>
< / XSL:模板>
< / XSL:样式>输出:
< P> 1线474; BR /> 2线474; BR /> 3线474; BR />< / P>
渲染为(实际标记):
1号线
2号线
3号线
I have some sample XML:
<sample><![CDATA[Line 1<br />Line 2<br />Line 3<br />]]></sample>
I'm using ASP to output this XML using a stylesheet like so:
Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP") xmlHttp.open "GET", URLxml, false xmlHttp.send() Set xslHttp = Server.CreateObject("Microsoft.XMLHTTP") xslHttp.open "GET", xXsl, false xslHttp.send() Set xmlDoc = Server.CreateObject("MICROSOFT.XMLDOM") Set xslDoc = Server.CreateObject("MICROSOFT.XMLDOM") xmlDoc.async = false xslDoc.async = false xmlDoc.Load xmlHttp.responseXML xslDoc.Load xslHttp.responseXML Response.Write xmlDoc.transformNode(xslDoc)
However, once this is getting written, the HTML output is showing up as:
Line 1<br />Line 2<br />Line 3
I can see that ASP is converting the brackets in the code, but I'm not sure why. Any thoughts?
解决方案I have some sample XML:
<sample><![CDATA[Line 1<br />Line 2<br />Line 3<br />]]></sample>
This is a
sample
element with a text node child.Suppose you apply an identity transform. Then the result will be:
<sample>Line 1<br />Line 2<br />Line 3<br /></sample>
Why? Because text nodes and attribute values have the special character
&
,<
and>
escape as character entities.EDIT: Of course, you could use DOE... But, besides that it's an optional feature, the result will be a text node no matter what (without the encode character entities). You will need other parser fase (this may be useful when output and encode HTML fragment to a (X)HTML document like in feeds, with the risk of malformed output...).
This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="sample"> <p> <xsl:value-of select="." disable-output-escaping="yes"/> </p> </xsl:template> </xsl:stylesheet>
Output:
<p>Line 1<br />Line 2<br />Line 3<br /></p>
Render as (actual markup):
Line 1
Line 2
Line 3这篇关于XML CDATA HTML里面正在转换与和放大器; LT;和&安培; GT;括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!