xml 如何在 XSD 中指定元素仅包含 CDATA?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/175695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:08:10  来源:igfitidea点击:

How do i designate in XSD that an element only contains CDATA?

xmlxsd

提问by Declan Shanaghy

How can I represent the following in XSD.

我如何在 XSD 中表示以下内容。

<price-update>
    <![CDATA[
      arbitrary data goes here
    ]]>
</price-update>

回答by James Curran

<element name="price-update" type="string"></element>  

is about as close as you can get.

尽可能接近。

(I thought it best to move the answer out of the comments and into an actual answer).

(我认为最好将答案从评论中移到实际答案中)。

回答by Oliver Hallam

A CDATA tag is merely a means of escaping data as a text node. Therefore you cannot stipulate that you require a CDATA node.

CDATA 标记只是将数据作为文本节点进行转义的一种方式。因此,您不能规定您需要 CDATA 节点。

From a DOM perspective, the following documents are identical:

从 DOM 的角度来看,以下文档是相同的:

<doc>value</doc>

and

<doc><![CDATA[value]]></doc>