can I get help on this please,
 
I'm trying to validate an XML document before using castor to unmarshal to java objects, but castor doesn't throw
MarshalException or ValidationException
 
for example, with the socks sample code,
 
try {
            System.out.println("Unmarshaling Socks");
            Socks socksDocument = Socks.unmarshal(new FileReader(args[0]));
            .......

     } catch (ValidationException ve) {
            System.out.println(ve.getMessage());
           ve.printStackTrace();
     } catch (MarshalException me) {
           System.out.println("Marshal Exception");
     } catch (Exception e) {
            e.printStackTrace();
    }
 
castor.properties looks like
--------------------------------------------------
org.exolab.castor.validation=true
org.exolab.castor.indent=true
org.exolab.castor.parser.validation=true
org.exolab.castor.parser=org.apache.xerces.parsers.SAXParser
org.exolab.castor.serializer=org.apache.xml.serialize.XMLSerializer
---------------------------------------------------------
 
and socks.xml
------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE socks SYSTEM "http://127.0.0.1:8080/socks.dtd">
<wrongroot>
    <sock number="1">
 <name>black socks</name>
 <image>blacksocks.jpg</image>
 <color>black</color>
 <price>9.99</price>
 <smell>7</smell>
    </sock>
</wrongroot>
-------------------------------------------------------
 
what I noticed is that castor doesn't throw any exception even though the XML document doesn't conform with the dtd.
 
the result I got was
-------------------------------------------------------------------------
Unmarshaling Socks
[Error] :-1:-1: Document root element "sockb", must match DOCTYPE root "socks".
[Error] :-1:-1: Element type "sockb" must be declared.
[Error] :-1:-1: Attribute "value" is required and must be specified for element type "color".
[Error] :-1:-1: The content of element type "color" must match "EMPTY".
[Error] :-1:-1: Attribute "value" is required and must be specified for element type "color".
[Error] :-1:-1: The content of element type "color" must match "EMPTY".
[Error] :-1:-1: Attribute "value" is required and must be specified for element type "color".
[Error] :-1:-1: The content of element type "color" must match "EMPTY".
Printing in memory socks...
Sock number 1 | Name: black socks | Color: black | Price: 9.99 | Smell: 7
.....
-----------------------------------------------------------------------------
 
Can anyone tell me what I need to do to get castor to throw an exception when XML docs doesn't match DTD when trying to umarshal XML doc to java.
 
Kind Regards
 
Yomi Ayodele
[EMAIL PROTECTED]

Reply via email to