Jump to content
Sign in to follow this  
XOR001

pattern element in xsd

Recommended Posts

Hi,i'm pretty new to xml and i got problems validating some file I wrote through an xsd that has been furnished by some third part company.Here is my concern about the code :<xs:element name="ChooseOne"><xs:simpleType><xs:restriction base="xs:string"><xs:pattern value=""/><xs:enumeration value="CHOICE1"/><xs:enumeration value="CHOICE2"/><xs:enumeration value="CHOICE3"/></xs:restriction></xs:simpleType></xs:element>so when I write at this level <ChooseOne>CHOICE1</ChooseOne> I got an error while trying to validate the xml file whether with XMLfox or XMLSpy saying the value for ChooseOne is incorrect (fun is that in XMLSpy when I edit the xml it is giving me CHOICE1,CHOICE2 or CHOICE3 in a scroll menu).It looks like the problme comes from that line that I don t understand :<xs:pattern value=""/>When I delete it the validation is working properly (if I put something else than CHOICE1,2 or 3 it is giving an error).Can any1 help me ?Thanks

Share this post


Link to post
Share on other sites

The pattern is a regular expression the value must match.The regular expression you have shows the value must be empty. And yet you allow those values. What you need to do is remove the pattern. If you want to allow the element to have an empty value, use "" as an enumeration instead.

Share this post


Link to post
Share on other sites

You can also express that enumeration as a regular expression

CHOICE[1-3]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...