This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes help requied for <restriction base=" title="" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "help requied for <restriction base="ID">" Watch "help requied for <restriction base="ID">" New topic

help requied for <restriction base="ID">

Dwijen Bhattacharjee

Joined: Mar 31, 2008
Posts: 26
Hi All,
I am completely new to the XSD . I have a requiremnt like that :
I have a element name Student of studenttype. It has an element name studentName and a attribute studentid(mandatory) (restrict values to 1- 1000)( make this ID).

So for that I have written the xsd like that

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="" targetNamespace=""
xmlns:tns="" elementFormDefault="qualified">
<simpleType name="studentType">
<restriction base="ID">
<pattern value="[1-99999]"></pattern>
<complexType name="Student">
<element name="studentName" type="string" />
<attribute name="studentid" use="required" type="studentIdType"
<element name="student" type="tns:studentType"></element>

now when I am trying to generarte the xml the it is like that " the value of the attribute studentid is not valid with resect to its type studentType"

can anyone tell me what I am doing wrong over here.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I'm almost certain that the regex you produced doesn't actually match all numbers between 1 and 1000. Or even between 1 and 99999. I suspect it might match any string which consists of a digit followed by four 9's, but I'm no regex expert.
Dwijen Bhattacharjee

Joined: Mar 31, 2008
Posts: 26
okey I think need to make my question more concise.. My query is suppose I have a attribute like studentId which must be unique and must be within the range 1 to 1000.

so for that my approach was
<simpleType name="studentIdType">
<restriction base="ID"> <!-- This will make the studentId unique-->
<pattern value="[1-1000]"></pattern> <!-- This will restrict the value within 1 to 1000-->

<attribute name="Studentid" use="required" type="studentIdType"></attribute>

whether this is correct way to write the requirement. Please assume the pattern is correct .
The problem I am facing that, If I generate any xml for this, Its not accepting the value for the attribute Studentid. I tried with 0 , 1 and some other random value.
its seems to me that its not accepting any number at all.

So please can anyone help me out why I am doing wrong.
I agree. Here's the link:
subject: help requied for <restriction base="ID">
It's not a secret anymore!