是否有任何 XSD 边缘情况允许文本节点内的 XML 元素内容?



是否有任何 XSD 边缘情况允许文本节点内的(未转义的(XML 元素内容? 例如,您可以将 CDATA 元素放在定义为 xs:string 的标签中并对其进行验证(不声明混合内容(吗?

如果你有一个包含字符串的元素,即

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2018 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root" type="xs:string" />
</xs:schema>

然后可以包含CDATA,即

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2018 (https://www.liquid-technologies.com) -->
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:TempXSDFile2.xsd">
Optional Text
<![CDATA[
<someXmlData></someXmlData>
]]>
Optional Text
</Root>

当它通过一些解析器时,它可能会转义回此,但两者都是有效且等效的。

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2018 (https://www.liquid-technologies.com) -->
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XSDFile2.xsd">
Optional Text
&lt;someXmlData&gt;&lt;/someXmlData&gt;
Optional Text
</Root>

最新更新