Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is anybody have solution for this...

 
arun sharma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using DOM- Apache Xerces 2.4.0 and Schema to validate a simple document , BUt I am getting this error:
--------------------------------------------
Error: URI=file:///D:/Test/XML/Test.xml Line=2: Document is invalid: no grammar found.
Error: URI=file:///D:/Test/XML/Test.xml Line=2: Document root element "NAME", must match DOCTYPE root "null".
-----------------------------------------------
This is the code i am usinf
----------------
XML File
--------------
<?xml version="1.0" encoding="UTF-8"?>
<NAME
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<FIRST_NAME>Arun</FIRST_NAME>
<LAST_NAME>Sharma</LAST_NAME>
</NAME>
-------------
Schema File:
------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="NAME">
<xs:complexType>
<xs:sequence>
<xs:element name="FIRST_NAME" type="xs:string"/>
<xs:element name="LAST_NAME" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
-------------
Java File
----------------
import javax.xml.parsers.*;
import java.io.*;
public class ActaSU {
public ActaSU() {
}
public static void main(String[] args) {
//ProductEventHandler producteventhandler = new ProductEventHandler();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", new File("test.xsd"));
//db.setErrorHandler(producteventhandler);
db.parse("Test.xml");
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
 
arun sharma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Roshan Lal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun,
Today I faced the same problem and came to this site for some pointers.
Just now my problem got solved. I had to put the xerces.jar ahead of all
other jars. Looks like there were other parsers in the classpath.
Try this and see if that helps.
-Roshan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic