user1349523
user1349523

Reputation: 41

How to represent a single element with attributes in XML schema?

I have an question about XML schema.

I've tried to explain a single element as below, but it have failed.

<parent-element>
    <check-element type="same">string value</check-element>
</parent-element>

What's wrong with that?

Upvotes: 1

Views: 115

Answers (1)

user1349523
user1349523

Reputation: 41

I've solved this question myself. ;)

<xs:complexType name="check-type">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="check"/>
      </xs:extension>
    </xs:simpleContent>
</xs:complexType>

<xs:element name="parent-element">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="check-element" type="target:check-type" minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Upvotes: 1

Related Questions