应该将xsd文档注释中的xml示例转义? [英] Should example xml in an xsd documentation annotation be escaped?
问题描述
例如:
<注释>
< documentation>示例Xml:& lt; element& gt;一些文本& lt; / element& gt< / documentation>
< / annotation>
或:
code><注释>
< documentation>示例Xml:< element>一些文本< / element>< / documentation>
< / annotation>
XmlSpy 2009似乎试图验证示例xml,在这种情况下,这是我没有的Oasis 8.1写和失败。如果我逃避xml,XML Spy的模式显示视图不会解开& lt;和& gt。。
看起来正确的做法是包括未转义的xml。 XML In A Nutshell Third Edition 显示了一个第282页的示例,其中有一个锚标签一个xsd框,但不包括在包含正在使用的模式的示例的文档的情况下做什么。
妥协:将示例未转义,但将它们封装在<![CDATA [...]]>
块中。这样可以防止XML Spy尝试验证您的示例,而不需要转义。
< annotation>
< documentation><![CDATA [Example Xml:< element> some text< / element>]]>< / documentation>
< / annotation>
Lets say I have an xsd schema and I have several <annotation/> elements with <documentation/> elements in them. If I wanted to place example xml in the <documentation/> elements, should I escape the example xml?
e.g.:
<annotation>
<documentation>Example Xml: <element>some text</element></documentation>
</annotation>
or:
<annotation>
<documentation>Example Xml: <element>some text</element></documentation>
</annotation>
XmlSpy 2009 seems to try to validate example xml, which in this case is Oasis 8.1 which I did not write, and fails. If I escape the xml, the schema display view of XML Spy does not unescape the < and >.
It would seem the correct thing to do is include the un-escaped xml. XML In A Nutshell Third Edition shows an example on page 282 where there is an anchor tag in an xsd box, but does not recommend specifically what to do in cases of the documentation containing examples of the schema being used..
Compromise: leave the examples unescaped, but wrap them in a <![CDATA[ ... ]]>
block. This should prevent XML Spy from attempting to validate your examples without requiring they be escaped.
<annotation>
<documentation><![CDATA[Example Xml: <element>some text</element>]]></documentation>
</annotation>
这篇关于应该将xsd文档注释中的xml示例转义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!