views:

22

answers:

1

I'm trying to create xsd for an element like this:

<ElementType attr1="a" attr2 ="b">mandatory_string</ElementType>

and I want to make the mandatory_string required. What should I add to this xsd:

<xs:complexType name="ElementType">
 <xs:simpleContent>
  <xs:extension base="xs:string">
   <xs:attribute name="attr1" type="StringLength1to2" use="required"/>
   <xs:attribute name="attr2" type="StringLength1to2" use="required"/>
  </xs:extension>
 </xs:simpleContent>
</xs:complexType>

Currently is optional. What's missing?

A: 

As mentioned in the comment the only way I know of is to use 'restriction's there is a restriction of 'pattern':

<xs:simpleType name="orderidtype">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{6}"/>
    </xs:restriction>
</xs:simpleType>

I am not sure that is exactly what you are looking for though. Are you wondering if you can make the entire tag required, or just the string itself? If just the string you could just use a regex expression in the above example.

__nv__
So using my and your example it should look like:<xs:complexType name="ElementType"> <xs:simpleContent> <xs:extension base="orderidtype"> <xs:attribute name="attr1" type="StringLength1to2" use="required"/> <xs:attribute name="attr2" type="StringLength1to2" use="required"/> </xs:extension> </xs:simpleContent></xs:complexType>right?
Guarava Makanili
I was imagining something more like:<xs:complexType> <xs:element name="ElementType" minOccurs="1" maxOccurs="1"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1"/> <xs:maxLength value="100"/> <!-- or --> <xs:pattern value="\w{1-100}"/> </xs:restriction> </xs:simpleType> <xs:attribute name="attr1" type="StringLength1to2" use="required"/> <xs:attribute name="attr2" type="StringLength1to2" use="required"/> </xs:element></xs:complexType>This would restrict the string from 1-100 characters. You can use one of the restrictions.
__nv__