Hi!
I'd like to validate against an XML Schema when unmarshalling. I've determined that I
need to set
org.exolab.castor.parser.validation=true
in order for Castor to attempt validation. However, it now appears to not be able to
find the schema. When I validate my schema instance against the schema using Xerces
directly in a small test program (SAXCount that comes with Xerces) it works as
expected. However, when I use Castor, I get an exception. If I've set
parser.validation to false, the instance doc is read just fine (without validation of
course).
Here are the first few lines of my schema (modified slightly from the Invoice example
that comes with Castor, the remainder of the doc is the same):
<?xml version="1.0"?>
<xsd:schema targetNamespace="autodesk.com/invoice"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="autodesk.com/invoice"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:annotation>
<xsd:documentation>
This is a test XML Schema for Castor XML.
</xsd:documentation>
</xsd:annotation>
etc.
Here are the first few lines of my instance (modified slightly from the Invoice
example, the remainder of the doc is the same):
<?xml version="1.0"?>
<invoice xmlns="autodesk.com/invoice"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="autodesk.com/invoice
file:///oem/castor-0.9.3.9/examples/SourceGenerator/invoice.xsd">
<ship-to>
<name>Ryan Madden</name>
<address>
<street1>2000 Alameda de las Pulgas</street1>
<city>San Mateo</city>
<state>CA</state>
etc.
Finally, here is the exception and stack trace that is thrown:
Unmarshalling Invoice
org.xml.sax.SAXException: Parsing Error : Element type "invoice" must be declare
d.
Line : 4
Column : 115
at org.exolab.castor.xml.UnmarshalHandler.error(UnmarshalHandler.java:11
08)
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1249
)
at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXML
Error(XMLValidator.java:1807)
at org.apache.xerces.validators.common.XMLValidator.validateElementAndAt
tributes(XMLValidator.java:3633)
at org.apache.xerces.validators.common.XMLValidator.callStartElement(XML
Validator.java:1229)
at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumen
tScanner.java:1806)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:949)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:338)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:270)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:391)
at test.Invoice.unmarshal(Invoice.java:258)
at InvoiceTest.main(InvoiceTest.java:83)
Thank you!
Chuck
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev