Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why it is happening like this...

 
arun sharma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still I am getting the same error in case of DOM ,,,can some tell me how to setFeature as we do in SAX...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic