0

With Xerces, I am getting following Error:

Parsing error:  Document is invalid: no grammar found.
Parsing error:  Document root element "TXLife", must match DOCTYPE root "null".

I have resolved the issue by setting

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ACORD.org/Standards/Life/2 file:///C:/Users/Himanshuy/workspace/XMLUnit/TXLife2.26.00.xsd" xmlns="http://ACORD.org/Standards/Life/2"

But now SAXParser is giving incorrect validation error when I compare it with XMLSpy validation error. SAXParser is giving me:

Invalid content was found starting with element <element>

XMLSpy is telling me:

<element> is not allowed at this location under element <some_parent_element>

Here XMLSpy is correct.

How can I get the same result from Java Validation?

Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291
  • possible duplicate of [What's the best way to validate an XML file against an XSD file?](http://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file) – daveb Apr 09 '12 at 16:16
  • That should work. Are you sure that your files exist (when you call `new File("...")`)? I ask because you aren't giving the path from root. If those files do exist, can you post the stack that you're getting? – Tim Pote Apr 09 '12 at 16:22
  • @TimPote Yes. Files do exist. Stacktrace: 'org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'TXLife'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)' – Himanshu Yadav Apr 09 '12 at 16:58
  • @daveb I have gone through the link you have mentioned. – Himanshu Yadav Apr 09 '12 at 17:12
  • @HimanshuYadav Can you post the xsd? – Tim Pote Apr 09 '12 at 17:18
  • @TimPote It's more than 20,000 lines. Not possible to post it here. – Himanshu Yadav Apr 09 '12 at 17:21
  • @HimanshuYadav I found this [site](http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXPSAX9.html) which deals with a similar error. Search for "Experimenting with Validation Errors". – Tim Pote Apr 09 '12 at 17:23
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9865/discussion-between-tim-pote-and-himanshu-yadav) – Tim Pote Apr 09 '12 at 17:25

0 Answers0