Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
anish reddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20769
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic