强制使用 XSD 中的属性

Forcing use of attributes in XSD

嗨,我想在我的 XSD
中强制使用此属性 现在这个属性是可选的

属性:

<xs:attribute name="namespace" type="xs:string"/>
<xs:attribute name="uri" type="xs:string"/>
<xs:attribute name="beforeMiddleware" type="xs:string"/>
<xs:attribute name="afterMiddleware" type="xs:string"/>
<xs:attribute name="accessLevel" type="xs:string"/>  

还有我的 XSD 文件:

<?xml version="1.0"?>
<xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        version="1.0"
        elementFormDefault="qualified"
        targetNamespace="grif:route"
>

    <xs:element name="routes">
        <xs:complexType>
           <xs:sequence>
                <xs:element name="group" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                             <xs:element name="route" minOccurs="0" maxOccurs="unbounded">
                               <xs:complexType>
                                   <xs:complexContent>
                                       <xs:restriction base="xs:string">
                                           <xs:attribute name="action" type="xs:string"/>
                                           <xs:attribute name="uri" type="xs:string"/>
                                           <xs:attribute name="method" type="methodList" default="GET"/>
                                       </xs:restriction>
                                   </xs:complexContent>
                               </xs:complexType>
                           </xs:element>
                        </xs:sequence>

                        <xs:attribute name="namespace" type="xs:string"/>
                        <xs:attribute name="uri" type="xs:string"/>
                        <xs:attribute name="beforeMiddleware" type="xs:string"/>
                        <xs:attribute name="afterMiddleware" type="xs:string"/>
                        <xs:attribute name="accessLevel" type="xs:string"/>
                    </xs:complexType>
                </xs:element>
           </xs:sequence>
        </xs:complexType>
    </xs:element>


    <xs:simpleType name="methodList">
        <xs:restriction base="xs:string">
            <xs:enumeration value="GET" />
            <xs:enumeration value="POST" />
            <xs:enumeration value="PUT" />
            <xs:enumeration value="HEAD" />
            <xs:enumeration value="DELETE" />
            <xs:enumeration value="CONNECT" />
            <xs:enumeration value="OPTIONS" />
            <xs:enumeration value="TRACE" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

我的示例 XML 文件是:

<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="grif:route">
    <group uri="/magazine" namespace="\Grif\Beans\BlogBeans" beforeMiddleware="LoginAuth">
        <route method="POST" action="NewsController@show" uri="/showNews" />
        <route method="GET" action="NewsController@archive" uri="/news" />
    </group>


    <group uri="/magazine/gallery" namespace="\Grif\Beans\MagazineBeans" accessLevel="ADMIN_ROLE">
        <route action="GalleryController@show" uri="/showGallery" />
    </group>
</routes>

如何改成强制使用属性???
怎么改成强制使用属性???
如何更改它以强制使用属性???

Attributes are optional by default. To specify that the attribute is required, use the "use" attribute:

<xs:attribute name="lang" type="xs:string" use="required"/>

参考:http://www.w3schools.com/xml/schema_simple_attributes.asp