简体   繁体   中英

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM