如何为带参数的标签定义XML模式?

时间:2013-05-29 12:40:44

标签: xml tags

我知道如何为标签内的简单实体定义xml架构。我们如何为带参数的标签定义xml架构?

<logins>
<login type="uname" value="robert"/>
<login type="name"  value="robert williams" />
</login>

我知道

<?xml version="1.0" encoding="UTF-8"?>
  <xs:schema>
    <xs: element name="login">
  <xs:complexType>
  <xs:sequence>

         <!-- What will come here ??-->
       </xs:sequence>
       </xs:complexType>
      </xs:element>
    </xs:schema>

1 个答案:

答案 0 :(得分:2)

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
    elementFormDefault="qualified"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:complexType name ="loginType">
    <xs:attribute name ="name" type ="xs:string" use="required"/>
    <xs:attribute name ="value" type ="xs:string" use="required"/>
  </xs:complexType>

  <xs:complexType name ="loginsType">
    <xs:sequence>
      <xs:sequence>
        <xs:element name="login" type ="loginType" minOccurs ="1" maxOccurs ="unbounded" />
      </xs:sequence>
    </xs:sequence>
  </xs:complexType>

  <xs:element name ="logins" type ="loginsType"/>
</xs:schema>