learn java
The moose likes XML and Related Technologies and the fly likes Is anybody have solution for this... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Is anybody have solution for this..." Watch "Is anybody have solution for this..." New topic

Is anybody have solution for this...

arun sharma

Joined: Jul 02, 2003
Posts: 19
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"?>
Schema File:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="NAME">
<xs:element name="FIRST_NAME" type="xs:string"/>
<xs:element name="LAST_NAME" type="xs:string"/>
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();
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"));
} catch (Exception exception) {
arun sharma

Joined: Jul 02, 2003
Posts: 19
Roshan Lal
Ranch Hand

Joined: Nov 13, 2001
Posts: 64
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Is anybody have solution for this...