Xml xsd的processContents strict vs lax vs skip:any

Xml xsd的processContents strict vs lax vs skip:any,xml,xsd,Xml,Xsd,master.xsd: <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.gworks.cn/waf_profile" xmlns:tns="http://www.gworks.cn/waf_profile" elementFormDefault="qualified"> &l

master.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.gworks.cn/waf_profile"
    xmlns:tns="http://www.gworks.cn/waf_profile" elementFormDefault="qualified">
    <element name="profile">
        <complexType>
            <sequence>
                <element name="aspect">
                    <complexType>
                        <sequence minOccurs="1" >
                            <any processContents="strict" />
                        </sequence>
                        <attribute name="id" type="string" use="required"></attribute>
                        <attribute name="class" type="string" use="required"></attribute>
                        <attribute name="desc" type="string" use="optional"></attribute>
                    </complexType>
                </element>
            </sequence>
            <attribute name="name" type="string" use="required"></attribute>
        </complexType>
    </element>
</schema>

我是否可以针对此架构编写XML文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<profile name="开发" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.gworks.cn/waf_profile"
    xsi:schemaLocation="http://www.gworks.cn/waf_profile http://www.gworks.cn/waf_profile.xsd">
    <aspect id="security" class="cn.gworks.waf.config.SecurityConfig" desc="安全配置">
        <security xsi:schemaLocation="http://www.gworks.cn/config_security http://www.gworks.cn/config_security.xsd">
            <authService impl="com.bgzchina.ccms.security.SSOAuthService" enabled="true">
                <certificate>
                    <field name="Token" isKey="true" />
                </certificate>
            </authService>
            <authService impl="com.bgzchina.ccms.security.NoAuthService" enabled="true">
                <certificate>
                    <field name="username" isKey="true" />
                </certificate>
            </authService>
        </security>
    </aspect>
</profile>


其中子元素“security”定义了自己的模式。

,因为XSD指定

<any processContents="strict" />
您的XML将是有效的,如果您在XSD中定义
安全性
,则该定义将在验证期间使用。(如果找不到定义,您的文档仍将被视为有效。)这要求内容只有在XML处理器可以找到其定义时才有效

如果你把这个改成

<any processContents="lax" />
<any processContents="skip" />
有关更多信息,请参见XSD建议中的

  • 如果您想知道如何将另一个XSD引入您的主机 XSD,请参阅

  • 在我的“security”元素上指定xsi:schemaLocation属性是否有效?否,您可以通过
    XSD:import
    XSD:include
    上的
    xsi:schemaLocation
    属性,将包含
    security
    声明的XSD带到主XSD中。但是我想让用户为任意元素指定模式。可以为XML中的元素指定类型通过
    xsi:type
    创建文档,但类型必须在XSDs中定义。xsd是使用
    xsd:import
    xsd:include
    组成的。您可以将
    xsi:schemaLocation
    用于这些。您还可以对XML文档实例的根元素使用
    xsi:schemaLocation