This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
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 Soft Skills this week in the Jobs Discussion 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
Author

Is anybody have solution for this...

arun sharma
Greenhorn

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"?>
<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

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.
-Roshan
 
 
subject: Is anybody have solution for this...