应该将xsd文档注释中的xml示例转义? [英] Should example xml in an xsd documentation annotation be escaped?

查看:157
本文介绍了应该将xsd文档注释中的xml示例转义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个xsd模式,我有几个< annotation /> < documentation />的元素其中的元素。如果我想将示例xml放在< documentation />元素,我应该逃避例子xml吗?



例如:

  <注释> 
< 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: &lt;element&gt;some text&lt;/element&gt;</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 &lt; and &gt;.

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屋!

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