<xs:element name="Credentials">
<xs:complexType>
<xs:attribute name="accountID" type="xs:string" use="required"/>
<xs:attribute name="username" type="xs:string" use="required"/>
<xs:attribute name="password" type="xs:string" use="required"/>
<xs:attribute name="cred1" type="xs:string"/>
<xs:attribute name="cred2" type="xs:string"/>
<xs:attribute name="cred3" type="xs:string"/>
<xs:attribute name="cred4" type="xs:string"/>
<xs:attribute name="cred5" type="xs:string"/>
<xs:attribute name="cred6" type="xs:string"/>
<xs:attribute name="cred7" type="xs:string"/>
<xs:attribute name="cred8" type="xs:string"/>
<xs:attribute name="cred9" type="xs:string"/>
<xs:attribute name="cred10" type="xs:string"/>
<xs:attribute name="cred11" type="xs:string"/>
<xs:attribute name="cred12" type="xs:string"/>
<xs:attribute name="cred13" type="xs:string"/>
<xs:attribute name="cred14" type="xs:string"/>
<xs:attribute name="cred15" type="xs:string"/>
<xs:attribute name="cred16" type="xs:string"/>
<xs:attribute name="cred17" type="xs:string"/>
<xs:attribute name="cred18" type="xs:string"/>
<xs:attribute name="cred19" type="xs:string"/>
<xs:attribute name="cred20" type="xs:string"/>
</xs:complexType>
<xs:element name="Credentials">
<xs:complexType>
<xs:attribute name="accountID" type="xs:string" use="required"/>
<xs:attribute name="username" type="xs:string" use="required"/>
<xs:attribute name="password" type="xs:string" use="required"/>
<!-- 0 or more of these attributes below - even 100 but I doubt I would need 100 for anything - i.e. optional -->
<xs:attribute name=don't care, but it should have a name" type="xs:string"/>
</xs:complexType>
<Credentials accountID="abc" username="me" password="mine"/>
<Credentials accountID="abc" username="me" password="mine" foo="bar"/>
<Credentials accountID="abc" username="me" password="mine" apples="oranges" fruit="sweet" just="another attribute"/>
答案 0 :(得分:2)
如果您想允许任何属性,请使用xs:anyAttribute
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Credentials">
<xs:complexType>
<xs:attribute name="accountID" type="xs:string" use="required"/>
<xs:attribute name="username" type="xs:string" use="required"/>
<xs:attribute name="password" type="xs:string" use="required"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:schema>
processContents
:
skip
允许任何属性,忽略任何声明。lax
允许任何属性,但需要声明验证
属性。strict
仅允许声明的属性进行验证
成功。