Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsd and null string

Status
Not open for further replies.

antobx

Programmer
May 15, 2008
2
IT
Hi,
I'm working with xml string validation against xsd schema.

I'm facing this problem . This is my xml string :

<A>
<Code></Code>
</A>

<Code> value is : 'A' , 'B' or empty string ('').
'A' , 'B' in lower and upper case .

xsd element definition :
<xs:element name="Code" type="tCode" minOccurs="0" maxOccurs="1" />

My simpletype :

<xs:simpleType name="tCode">
<xs:restriction base="xs:string">
<xs:pattern value="((A|a)|(B|b))"/>
</xs:restriction>
</xs:simpleType>

This works fine with 'A' and 'B' . I can't validate null /empty string . What is the right definition ?
Could you help me ?
Thanks in advance .
 
>I can't validate null /empty string . What is the right definition ?
Change the pattern accrodingly?
><xs:pattern value="((A|a)|(B|b))"/>
[tt]<xs:pattern value="((A|a)|(B|b))?"/>[/tt]

 

thankyou tsuji !


I found this too :

<xs:simpleType name="tCode">
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="((A|a)|(B|b))"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
 
That can do, but it consists of a largely unnecessary twist.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top