You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Greg Zoller <gz...@hotmail.com> on 2000/12/15 06:55:16 UTC
Schemas Not Catching Errors?
Hello. I'm trying to get Xerces to validate using XML schema.
I've turned on the validation feature in my 15-line Java program
that does nothing but parse the doc and report exceptions.
Here's my xsd:
<?xml version="1.0" encoding="UTF-8"?>
<schema>
<ElementType name="description" content="textOnly"
model="closed"/>
<ElementType name="role" content="eltOnly" model="closed">
<element type="description" minOccurs="1"
maxOccurs="1"/>
<AttributeType name="name" />
<attribute type="name" />
</ElementType>
<element type="role" />
</schema>
And my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Top xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='schema.xsd' >
<role name="hey">
</role>
</Top>
This should give me an error because the <role> tag is missing
the required <description> tag, but my parser happily accepts this
with no problems.
Just as a sanity check I played with the included personnel-schema.xml
example. In theory at least 1 <person> element is required in the
<personnel> element, but if I delete all the <person> elements my
parser is still happy!
Anyone see what I'm doing wrong?
Thanks
Greg
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: Schemas Not Catching Errors?
Posted by Eric Ye <er...@locus.apache.org>.
You need to have a errorhandler and register it on the parser, for detail,
please refer to sax.SAXCount sample under samples directory.
Eric Ye
IBM-Cupertino.
----- Original Message -----
From: "Greg Zoller" <gz...@hotmail.com>
To: <xe...@xml.apache.org>
Sent: Friday, December 15, 2000 5:55 AM
Subject: Schemas Not Catching Errors?
> Hello. I'm trying to get Xerces to validate using XML schema.
> I've turned on the validation feature in my 15-line Java program
> that does nothing but parse the doc and report exceptions.
>
> Here's my xsd:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema>
> <ElementType name="description" content="textOnly"
> model="closed"/>
> <ElementType name="role" content="eltOnly" model="closed">
> <element type="description" minOccurs="1"
> maxOccurs="1"/>
> <AttributeType name="name" />
> <attribute type="name" />
> </ElementType>
> <element type="role" />
> </schema>
>
> And my XML file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Top xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation='schema.xsd' >
>
> <role name="hey">
> </role>
> </Top>
>
> This should give me an error because the <role> tag is missing
> the required <description> tag, but my parser happily accepts this
> with no problems.
>
> Just as a sanity check I played with the included personnel-schema.xml
> example. In theory at least 1 <person> element is required in the
> <personnel> element, but if I delete all the <person> elements my
> parser is still happy!
>
> Anyone see what I'm doing wrong?
>
> Thanks
> Greg
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>