wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

help requied for <restriction base="ID">

Dwijen Bhattacharjee
Greenhorn

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="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/studeent"
xmlns:tns="http://www.example.org/studeent" elementFormDefault="qualified">
<simpleType name="studentType">
<restriction base="ID">
<pattern value="[1-99999]"></pattern>
</restriction>
</simpleType>
<complexType name="Student">
<sequence>
<element name="studentName" type="string" />
</sequence>
<attribute name="studentid" use="required" type="studentIdType"
use="required"></attribute>
</complexType>
<element name="student" type="tns:studentType"></element>
</schema>

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Greenhorn

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-->
</restriction>
</simpleType>

and
<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.
 
 
subject: help requied for <restriction base="ID">
 
Similar Threads
schema error : undefined value for 'type' encountered
override an attribute from parent element?
XML Schema: Use of Import
Defining XSD for an XML file with constraint on the contents of a tag
Error in xml schema