关于在XML文件中对<>&特殊标记的处理
在XML中<、>、&三个符号不被XML所认知,不管是在节点中的文本还是,节点的属性值,均无法被认知。
处理方法1:
将三个符号分别进行转换
< <
> >
& &
处理方法2:
当数据中有许多地方出现特殊符号的时候,建议这样做:
躲避语法检查的方法-CDATA 
  CDATA内的数据内容都会被当作文本来处理,从而避开语法检查,直接作为文本显示。示例: 
  < ! [ CDATA [ this ia <b> a test ] ] > 
  显示结果为 
  this ia <b> a test 
值得注意的是:
处理方法2中如果是使用XML+XSL与HTML相结合,那么在XSL文件中应该如此
<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:template match="/entry"> 
<html> 
<head> 
</head> 
<body> 
<xsl:value-of select="title" /> 
<xsl:value-of select="body" disable-output-escaping="yes"/> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet>
关键之外在于使用的命名空间xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 和输出时加上disable-output-escaping="yes"
其核心就是利用 disable-output-escaping="yes" 
MSDN 上对它的描述如下:
disable-output-escaping 
Default is "no". If the value is "yes", a text node generated by instantiating the element will be output without any escaping. For example, the following generates the single character "<". 
<
Note?? disable-output-escaping="yes" can be used to generate non-well-formed documents, and thus should be used with caution, because non-well-formed output may generate errors in certain circumstances. For example, transformNodeToObject to an XML document requires that the result be well-formed and thus may not complete ifdisable-output-escaping has affected the well-formedness of the document. Consider disable-output-escaping="yes" an advanced feature to be used only when the potential dangers are understood.
 
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号