Announcement Announcement Module
Collapse
No announcement yet.
XSD validation with CastorMarshaller from Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XSD validation with CastorMarshaller from Spring

    I am using Spring CastorMarshaller for unmarshalling from xml-> Java.
    I want to validate the xml against the xsd before unmarshalling it.

    I have enabled validation using the following in castor.properties file.

    org.exolab.castor.parser.validation=true

    # Comma separated list of SAX 2 features that should be enabled for the
    # default parser.
    #
    org.exolab.castor.sax.features=http://xml.org/sax/features/validation,\
    http://apache.org/xml/features/validation/schema,\
    http://apache.org/xml/features/valid...-full-checking

    # True for parser to support Namespaces.
    # Defaults to false.
    #
    org.exolab.castor.parser.namespaces=true

    # Defines the default XML parser to be used by Castor.
    org.exolab.castor.parser=com.sun.org.apache.xerces .internal.parsers.SAXParser

    The xml file has correct schema defined in xsi:schemaLocation.

    But I always get this trace while unmarshal
    Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'rankings'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:236)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.error(ErrorHandlerWrapper.java:172)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:382)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:316)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.handleStartElement(XMLSchemaValidator. java:1944)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.startElement(XMLSchemaValidator.java:7 05)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:330)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl$NSContentDispatcher.scanRootElement Hook(XMLNSDocumentScannerImpl.java:779)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDispatcher.dis patch(XMLDocumentFragmentScannerImpl.java:1794)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:368)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:834)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:148)
    at com.sun.org.apache.xerces.internal.parsers.Abstrac tSAXParser.parse(AbstractSAXParser.java:1242)
    at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmar shaller.java:715)


    Appreciate your help.
    Thanks in advance.
Working...
X