Как объявить элемент только с атрибутами в XML-схеме? - PullRequest
8 голосов
/ 10 января 2012

Дано:

<authentication password="turkey" partnerid="exam" />

как я могу объявить этот элемент в схеме XML?

У меня есть:

<xs:element name="authentication" type="auth_type" />

<xs:complexType name ="auth_type">
  <xs:simpleContent>
    <xs:extension base="xs:string">
      <xs:attribute name="password" type="xs:string" />
      <xs:attribute name="partnerid" type="xs:string" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

но это позволит элементу иметь текстовое содержимое, не так ли? Я не хочу этого ...

Ответы [ 2 ]

16 голосов
/ 10 января 2012

Вы можете удалить xs:simpleContent и xs:extension ....

  <xs:element name="authentication" type="auth_type" />

  <xs:complexType name ="auth_type">
    <xs:attribute name="password" type="xs:string" />
    <xs:attribute name="partnerid" type="xs:string" />
  </xs:complexType>
0 голосов
/ 01 августа 2013

вам нужен сложный элемент, например:

<product prodid="1345" />

Элемент "product", приведенный выше, вообще не имеет содержимого.Чтобы определить тип без содержимого, мы должны определить тип, который допускает элементы в его содержимом, но мы фактически не объявляем какие-либо элементы, например:

<xs:element name="product">
  <xs:complexType>
    <xs:complexContent>
      <xs:restriction base="xs:integer">
        <xs:attribute name="prodid" type="xs:positiveInteger"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

check http://www.w3schools.com/schema/schema_complex_empty.asp

...