master.xsd:processContents строгого против Лакса против пропуска для 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>
, где "безопасность" дочернего элемента имеет свою собственную схему.
Действительно ли это указать атрибут xsi: schemaLocation в моем элементе «security»? – CaiNiaoCoder
Нет, вы бы принесли XSD, содержащий декларацию 'security', в ваш мастер XSD через атрибут xsi: schemaLocation' на' xsd: import' или 'xsd: include', как я упоминал в ответе. – kjhughes
Но я хочу дать пользователю указать схему для произвольного элемента. – CaiNiaoCoder