Schema attribute/pattern problem

Status
Not open for further replies.

vicky

Usenet Archive
Joined
Sep 26, 2001
Messages
84
Reaction score
0
In my schema file I am trying to set a pattern rule for an attribute <doc number="00-1234"> in my xml file. The code I have used is in the schema is:

.....
<xsd:complexType name="docType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/> ..... </xsd:element> <xsd:attribute name="number" type="numberType" use="required"/> </xsd:complexType>

<xsd:simpleType name="numberType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([0-9]){2}-([0-9]){4}"/>
</xsd:restriction>
</xsd:simpleType>

The pattern is correct, but when I validate my xml file against this using Xerces, I get the following error:
"List | Union | Restriction content is invalid for type numberType"

What do I need to do to sort out this problem?

Thanks

Vicky
 

Eric A. Sirois

Usenet Archive
Joined
Nov 28, 2000
Messages
25
Reaction score
0
Hello Vicky,

This should work for you.
<xsd:pattern value="[0-9]{2}-[0-9]{4}"/>

Cheers,

Eric

"Vicky" wrote:

In my schema file I am trying to set a pattern rule for an attribute <doc number="00-1234"> in my xml file. The code I have used is in the schema is:

.....
<xsd:complexType name="docType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/> ..... </xsd:element> <xsd:attribute name="number" type="numberType" use="required"/> ...
 

Antoine Benoit

Usenet Archive
Joined
Jan 30, 2002
Messages
18
Reaction score
0
Did you put a </xsd:element> tag instead of a </xsd:sequence> tag in your schema or is it just a copying mistake in your message ? (probably nothing to do with the problem, I was just wondering) The numerType definition looks ok, and works here on Xerces 1_4_4 (but I didn't use your docType) What's your version of Xerces ?

Antoine

Vicky wrote:
In my schema file I am trying to set a pattern rule for an attribute <doc number="00-1234"> in my xml file. The code I have used is in the schema is:

.....
<xsd:complexType name="docType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/> ..... </xsd:element> <xsd:attribute name="number" type="numberType" use="required"/> ...
 

Andre Levy

Usenet Archive
Joined
Jan 30, 2002
Messages
10
Reaction score
0
I do agree. it seems to me like your problem is not with the definition of numberType but somewhere BEFORE it.
is your schema well-formed?

Andre

Antoine Benoit wrote:

Did you put a </xsd:element> tag instead of a </xsd:sequence> tag in your schema or is it just a copying mistake in your message ? (probably nothing to do with the problem, I was just wondering) The numerType definition looks ok, and works here on Xerces 1_4_4 (but I didn't use your docType) What's your version of Xerces ?

Antoine

Vicky wrote:

>In my schema file I am trying to set a pattern rule for an attribute
><doc number="00-1234"> in my xml file. The code I have used is in the ...
 

vicky

Usenet Archive
Joined
Sep 26, 2001
Messages
84
Reaction score
0
Antoine,

Did you put a </xsd:element> tag instead of a </xsd:sequence> tag in your schema or is it just a copying mistake in your message ?

I have </xsd:sequence> in my schema - it was a typo in my message.

(probably nothing to do with the problem, I was just wondering) The numerType definition looks ok, and works here on Xerces 1_4_4 (but I didn't use your docType) What's your version of Xerces ?

I am using xerces-2_0_0_beta2.

Regards,

Vicky
 

vicky

Usenet Archive
Joined
Sep 26, 2001
Messages
84
Reaction score
0
Antoine,

A stripped down version of my xml file is:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="proc.xsl"?>

<Processes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="proc.xsd">

<doc number="44-0028">
<title>System Segmentation</title>
</doc>

<doc number="41-0003">
<title>Technical Writing Scheme</title>
</doc>

</Processes>

And the corresponding (but giving an error) schema file is:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xsd:element name="Processes">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="doc" type="docType" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>

<xsd:complexType name="docType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="number" type="numberType" use="required"/> </xsd:complexType>

<xsd:simpleType name="numberType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{2}-[0-9]{4}"/>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>

Hopefully, this may help you to find where I am going wrong.

Regards

Vicky
 

Antoine Benoit

Usenet Archive
Joined
Jan 30, 2002
Messages
18
Reaction score
0
Vicky,

I tried to parse your XML document with your schema, and it worked fine. I'm wondering if the problem doesn't simply come from the beta version of Xerces you're using. I really don't see anything wrong in your files.

Antoine
 

vicky

Usenet Archive
Joined
Sep 26, 2001
Messages
84
Reaction score
0
I have now tried to validate the xml with the schema using other xerces.jar files ie those included with Fop-0.20.2, xalan-j_2_2_D11, and batik, and end up with the same result. I wonder if it might be my java validation file that I have based on the SAX example bundled with xerces.

Thank you for your help and suggestions.

Vicky
 
Status
Not open for further replies.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top