ProcessContents strict vs lax vs skip for xsd: any

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> 

Can I write an XML file according to this scheme as follows:

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

where the child security element has its own schema.

+7
xml xsd
source share
1 answer

Because XSD indicates

 <any processContents="strict" /> 

in the aspect content model, your XML is not valid due to processContents="strict" , which requires the XML processor to have an XSD definition , in this case security and should be able to validate it .

If you change it to

 <any processContents="lax" /> 

your XML will be valid, and if you come to the definition of security in your XSD, the definition will be used during validation. (If a definition cannot be found, your document will still be considered valid.) This requires that the content be valid only if the XML processor can find its definition .

If you change it to

 <any processContents="skip" /> 

your XML will be valid, and the XML processor will not try to validate the contents of the child content in aspect (except that it must be a separate element to limit the sequence ).

Notes:

  • The default value for processContents is strict .
  • See section 3.10.2 Representation of XML Component Wildcards in the XSD Recommendation for more information.
  • If you're interested in how to bring another XSD to your XSD wizard, see xsd: import vs xsd: include .
+10
source share

All Articles