【问题标题】:Does any XSD edge case allow XML element content inside a text node?是否有任何 XSD 边缘案例允许文本节点内的 XML 元素内容?
【发布时间】:2017-12-23 08:33:45
【问题描述】:

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

【问题讨论】:

    标签: xsd xml-parsing escaping cdata


    【解决方案1】:

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

    <?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:\Temp\XSDFile2.xsd">
        Optional Text
        <![CDATA[
            <someXmlData></someXmlData>
        ]]>
        Optional Text
    </Root>
    

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

    <?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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-18
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多