在 xpath 中为什么我可以使用大于号 >但不小于 < [英] In xpath why can I use greater-than symbol > but not less-than <
问题描述
使用 c#3 编译转换以下似乎工作得很好...
<xsl:when test="$valA > $valB"><xsl:value-of select="$maxUnder"/></xsl:when><xsl:when test="$valA < $valC"><xsl:value-of select="$maxOver"/></xsl:when></xsl:选择>
但是,如果我敢使用 <
代替 <
它会给出错误...
<xsl:when test="$valA > $valB"><xsl:value-of select="$maxUnder"/></xsl:when><xsl:when test="$valA < $valC"><xsl:value-of select="$maxOver"/></xsl:when></xsl:选择>
<块引用>
System.Xml.XmlException: '<',十六进制值 0x3C,是无效的属性字符.
那么为什么 >
可以,而不是 <
?
因为 >
不是 XML 中的保留字符,而 <
是.>
与号字符 (&
) 和不得出现左尖括号 (<
)以它们的字面形式,除非用作标记分隔符,或在评论、处理指令,或CDATA 部分.如果他们需要在其他地方,它们必须使用数字字符引用或字符串&
"和<
"分别.右尖括号(>
) 可以使用字符串>
",并且必须,对于兼容性,使用任一方法进行转义">
" 或字符引用它出现在字符串]]>
"中内容,当该字符串不是标记 CDATA 部分的结尾.
Using c#3 compiled transforms the following seems to work just fine...
<xsl:choose>
<xsl:when test="$valA > $valB">
<xsl:value-of select="$maxUnder" />
</xsl:when>
<xsl:when test="$valA < $valC">
<xsl:value-of select="$maxOver" />
</xsl:when>
</xsl:choose>
However if i dare use a <
in place of <
it gives an error...
<xsl:choose>
<xsl:when test="$valA > $valB">
<xsl:value-of select="$maxUnder" />
</xsl:when>
<xsl:when test="$valA < $valC">
<xsl:value-of select="$maxOver" />
</xsl:when>
</xsl:choose>
System.Xml.XmlException: '<', hexadecimal value 0x3C, is an invalid attribute character.
So why is >
ok and not <
?
Because >
isn't a reserved character in XML, but <
is.
From section 2.4 of the XML 1.0 spec (5th edition):
The ampersand character (
&
) and the left angle bracket (<
) must not appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they must be escaped using either numeric character references or the strings "&
" and "<
" respectively. The right angle bracket (>
) may be represented using the string ">
", and must, for compatibility, be escaped using either ">
" or a character reference when it appears in the string "]]>
" in content, when that string is not marking the end of a CDATA section.
这篇关于在 xpath 中为什么我可以使用大于号 >但不小于 <的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!