Thanks Keith.
Here's a simple test case that I believe should fail when unmarshalled by
Castor, but doesn't.
fruitbowl.xsd
==========
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.xxx.yyy/ns/food"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.xxx.yyy/ns/food"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:element name="fruitbowl">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="banana" type="xsd:string"/>
<xsd:element name="pineapple" type="xsd:string"
minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
fruitbowl.xml
==========
<?xml version="1.0"?>
<fruitbowl xmlns="http://www.xxx.yyy/ns/food"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xxx.yyy/ns/food fruitbowl.xsd">
<!--- <banana>Boris</banana> Yes, we have no bananas..... and therefore
should fail -->
<pineapple>Peter</pineapple>
</fruitbowl>
Performed a default unmarshalling ( no mapping file, no pre-generated
descriptors ) using Castor:
xml = new InputStreamReader( getClass().getResourceAsStream( "/" +
FRUITBOWL_XML ) );
Unmarshaller unmar = new Unmarshaller( new FruitBowl().getClass(),
Unmarshaller.class.getClassLoader() );
unmar.setValidation( true );
FruitBowl fb = (FruitBowl) unmar.unmarshal( xml );
and got a NULL banana as expected, but where's my Schema validation exception.
Performed a parsing of the same file using the Xerces SAXParser:
xml = new InputStreamReader( getClass().getResourceAsStream( "/" +
FRUITBOWL_XML ) );
org.xml.sax.XMLReader parser = (org.xml.sax.XMLReader) new
org.apache.xerces.parsers.SAXParser();
parser.setErrorHandler( new cHandler() );
parser.setFeature( "http://xml.org/sax/features/validation", true );
parser.setFeature( "http://xml.org/sax/features/namespaces", true );
parser.setFeature( "http://apache.org/xml/features/validation/schema",
true );
parser.setFeature( "
http://apache.org/xml/features/validation/schema-full-checking", true );
parser.parse( new InputSource( xml ) );
and got the following exception as expected:
The content of element type "fruitbowl" must match "(banana,pineapple?)
Is the difference in behaviour due to Castor using the SAX 1 org.xml.sax.Parser
interface rather than the SAX 2 org.xml.sax.XMLReader interface ?
I've tried the following and again received no validation exception:
xml = new InputStreamReader( getClass().getResourceAsStream( "/" +
FRUITBOWL_XML ) );
org.xml.sax.Parser parser = (org.xml.sax.Parser) new
org.apache.xerces.parsers.SAXParser();
parser.setErrorHandler( new eHandler() );
parser.parse( new InputSource( xml ) );
Can I conclude that in order to receive Schema validation exceptions, Castor
would have to be changed to use the SAX 2 XMLReader interface ?
Thanks for any help,
Gary
The HSBC Group's website is at http://www.hsbc.com
************************************************************************
HSBC Bank plc, which is regulated in the UK by SFA, has issued the
information contained in this message (including any attached documents)
for its non-private customers only. This message and any attachments are
not an invitation to buy or sell securities or related financial instruments,
are confidential to the named recipient and may also be privileged. The
information should not be reproduced and/or distributed to any other
person. Internet communications are not secure and HSBC Bank plc
accepts no legal responsibility for the contents of this message.
HSBC Bank plc makes no representation and accepts no responsibility
or liability as to the completeness and accuracy of the information
contained in this message. Opinions may change without notice and
members of the HSBC Group may have positions in, or trade in instruments
mentioned in this message. Each page attached hereto must be read in
conjunction with any disclosure which forms part of it.
************************************************************************
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev