在 xpath 中为什么我可以使用大于号 >但不小于 < [英] In xpath why can I use greater-than symbol > but not less-than <

查看:35
本文介绍了在 xpath 中为什么我可以使用大于号 >但不小于 <的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 c#3 编译转换以下似乎工作得很好...

<xsl:when test="$valA > $valB"><xsl:value-of select="$maxUnder"/></xsl:when><xsl:when test="$valA &lt; $valC"><xsl:value-of select="$maxOver"/></xsl:when></xsl:选择>

但是,如果我敢使用 < 代替 &lt; 它会给出错误...

<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 中的保留字符,而 < 是.>

来自 XML 1.0 规范(第 5 版)第 2.4 节:

<块引用>

与号字符 (&) 和不得出现左尖括号 (<)以它们的字面形式,除非用作标记分隔符,或在评论、处理指令,或CDATA 部分.如果他们需要在其他地方,它们必须使用数字字符引用或字符串&amp;"和&lt;"分别.右尖括号(>) 可以使用字符串&gt;",并且必须,对于兼容性,使用任一方法进行转义"&gt;" 或字符引用它出现在字符串]]>"中内容,当该字符串不是标记 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 &lt; $valC">
        <xsl:value-of select="$maxOver" />
    </xsl:when>
</xsl:choose>

However if i dare use a < in place of &lt; 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 "&amp;" and "&lt;" respectively. The right angle bracket (>) may be represented using the string "&gt;", and must, for compatibility, be escaped using either "&gt;" 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 中为什么我可以使用大于号 &gt;但不小于 &lt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆