gpt4 book ai didi

xml - 为什么 < 不转换为 < while > 和其他转义字符适当转换

转载 作者:行者123 更新时间:2023-12-02 01:09:46 26 4
gpt4 key购买 nike

我通过 SoapUI 发送肥皂请求并使用 XSLT生成 XML回复。我的回复需要如下所示:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TXLifeResponse>
<TransType tc="1201">General Requirement Order Request</TransType>
</TXLifeResponse>
</soap:Body>
</soap:Envelope>

我可以从下面的XSLT得到这个回复

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:acord="http://ACORD.org/Standards/Life/2"
xmlns="http://ACORD.org/Standards/Life/2">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<xsl:variable name="TransType_tc" select="//acord:TXLife/acord:TXLifeRequest//acord:TransType/@tc" />
<xsl:variable name="TransType" select="//acord:TXLife/acord:TXLifeRequest//acord:TransType" />

<xsl:template match="/">
<TXLifeResponse>
<xsl:element name="TransType">
<xsl:attribute name="tc"><xsl:value-of select="$TransType_tc"/></xsl:attribute>
<xsl:value-of select="$TransType"/>
</xsl:element>
</TXLifeResponse>
</xsl:template>
</xsl:stylesheet>

但我注意到了一个意想不到的行为。使用前<xsl:element<xsl:attribute>标签,我在XSLT中做了类似的事情:

&lt;TransType tc=&quot;<xsl:value-of select="$TransType_tc"/>&quot;&gt;<xsl:value-of select="$TransType"/> &lt;/TransType&gt;

以及 SoapUI 中收到的输出是:

&lt;TransType tc="1201">General Requirement Order Request &lt;/TransType>

任何人都可以帮助我理解为什么 &lt;未转换,但 &gt;&quot;做到了。

谢谢

最佳答案

看看 syntax rules described in the XML specification :

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.

所以,这是合法的:

<xml> > </xml>

...但在这种情况下不会:

<xml> ]]&gt; </xml>

To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as &apos;, and the double-quote character (") as &quot;.

所以,这是合法的:

<xml attr=" ' " />

...但在这种情况下不会:

<xml attr=' &apos; ' />

一些转义编码器开发人员过于谨慎,或者更容易概括表示,因为您不需要了解太多有关转义数据的上下文。

关于xml - 为什么 < 不转换为 < while > 和其他转义字符适当转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14345208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com