0

For example, I want to create an element Title containing 3 choices: Mr., Mrs., Miss, so that users can only choose one of them. How can I do that? Is this something like:

<xs:complexType name="Title">
    <xs:sequence>
        <xs:choice maxOccurs="unbounded" minOccurs="0">
        Mr.
        </xs:choice>
        <xs:choice maxOccurs="unbounded" minOccurs="0">
        Mrs.
        </xs:choice>
        <xs:choice maxOccurs="unbounded" minOccurs="0">
        Miss
        </xs:choice>
   </xs:sequence>
</xs:complexType>
2
  • I am not aware that there is a specified way to do it in XML. To my knowledge, XML only represents data and not forms. Those would be found in XHTML / HTML code. All I can say is that you could use XSLT with this XML-schema to produce a valid XHTML / HTML dropdown control, yes. Commented Jul 26, 2013 at 20:31
  • oh, So all I have to do is just making it simple like: <xs:element name="Title" type="xs:string" maxOccurs="3" minOccurs="0"/> Commented Jul 26, 2013 at 20:38

1 Answer 1

2

Try using the xs:enumeration element. For example this schema restricts to documents with a single element 'Title' with 'Mr' or 'Ms' in it:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Title" type="Title"/>
  <xs:simpleType name="Title">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Mr"/>
      <xs:enumeration value="Ms"/>
    </xs:restriction>  
  </xs:simpleType>
</xs:schema>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. Is this necessary to write mstns in type="mstns:Title"?
No - I've edited the schema so that it doesn't include a namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.