File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes xml validation error:Caused by: nu.xom.ValidityException: Document is invalid: no grammar found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml validation error:Caused by: nu.xom.ValidityException: Document is invalid: no grammar found" Watch "xml validation error:Caused by: nu.xom.ValidityException: Document is invalid: no grammar found" New topic
Author

xml validation error:Caused by: nu.xom.ValidityException: Document is invalid: no grammar found

anish reddy
Ranch Hand

Joined: Apr 19, 2008
Posts: 74
hi all

iam passing an xml document and xsd from a remote or local ,when i try to validate xml with schema/dtd defined in it.
iam getting the error as

Caused by: nu.xom.ValidityException: Document is invalid: no grammar found. at line 2, column 10
at nu.xom.Builder$ValidityRequired.error(Unknown Source)..
But when i keep validation arg as false i am able to read xml document and any xml violation of schema those messages are displayed on console.
But when i keep validation arg as true.iam getting the above exception.

The reason i came to know is schema/dtd can not be found,so it is showing as unknown source.

please any one give idea how to resolve it or code to resolve this problem.

thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

The document contains a reference to a schema or a DTD? (You should be able to tell which it is, surely?) And the error message says the parser can't find that schema or DTD? Well, without seeing the document it's rather difficult to guess at what's going on. Perhaps the reference isn't a well-formed URL. Or perhaps it's a relative URL and the parser doesn't know what the system ID of the document is, because of how you chose to pass it to the parser. Or perhaps something else.

So... TellTheDetails. Show us the part of the document which refers to the schema or DTD. Show us the code which parses the document.
anish reddy
Ranch Hand

Joined: Apr 19, 2008
Posts: 74
this is my sample xml

<contacts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="contacts.xsd">
<contact title="citizen">
<firstname>Edwin</firstname>
<lastname>Dankert</lastname>
</contact>
</contacts>

this is my xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="contacts">
<xs:complexType>
<xs:sequence>
<xs:element ref="contact"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:NCName"/>
<xs:element name="lastname" type="xs:NCName"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

now i found my error i.e that schema can not be found.how to set schema for an xml pointing to uri or in local hardisk.

please need an idea to resolve this problem


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml validation error:Caused by: nu.xom.ValidityException: Document is invalid: no grammar found