It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes Why it is happening like this... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Why it is happening like this..." Watch "Why it is happening like this..." New topic
Author

Why it is happening like this...

arun sharma
Greenhorn

Joined: Jul 02, 2003
Posts: 19
Hi;
I am getting
-------------------------------
Error: Document is invalid: no grammar found.
Error: Document root element "NAME", must match DOCTYPE root "null".
---------------------------------------
I am having is simple XML Schema , XML file and Using Xerces 2.4 parser
I am attaching the XML , Schema and java file
------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<NAME
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="acta.xsd">
<FIRST_NAME>Arun</FIRST_NAME>
<LAST_NAME>Sharama</LAST_NAME>
</NAME>
------------------------------------------
<?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:integer" />
<xs:element name="LAST_NAME" type="xs:string" />
</s:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
-----------------------------------------
import java.io.File;

import javax.xml.parsers.*;
import javax.xml.parsers.*;
//import org.apache.xerces.parsers.SAXParser;

public class WellFormednessChecker {
public static void main(String[] args) {
ProductEventHandler handler = new ProductEventHandler();
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser sp = spf.newSAXParser();
sp.parse("Test.xml",handler);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
3 or 4 posts from the bottom talks about the error
http://forum.java.sun.com/thread.jsp?thread=408443&forum=427&message=1798537
Eric
arun sharma
Greenhorn

Joined: Jul 02, 2003
Posts: 19
Still I am getting the same error in case of DOM ,,,can some tell me how to setFeature as we do in SAX...
 
GeeCON Prague 2014
 
subject: Why it is happening like this...