views:

1118

answers:

2

I'm having difficulty searching for this. How would I define an element in an XML schema file that looks like this:

<option value="test">sometext</option>

I can't figure out how to define an element that is of type "xs:string" and also has an attribute. I'm fairly new to writing XML schemas, so please bear with me!

Here's what I've got so far (am I close? what am I missing?):

<xs:element name="option">
    <xs:complexType>
     <xs:attribute name="value" type="xs:string" />
    </xs:complexType>
</xs:element>
+11  A: 

Try

  <xs:element name="option" type="AttrElement" />

  <xs:complexType name="AttrElement">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="value" type="xs:string">
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
David Norman
+3  A: 

... or the inline equivalent:

<xs:element name="option">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="value" type="xs:string">
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>
Julian