File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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 following errors:
-------------------------------
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:string" />
<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();
}
}
}
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
you have turn on schema validation for this using setFeature
try the below code(got from ibm tutorial)https://www6.software.ibm.com/developerworks/education/x-xschema/x-xschema-4-1.html


Spritle Software Blogs
arun sharma
Greenhorn

Joined: Jul 02, 2003
Posts: 19
Hi Balaji;
I tried the same as u told but still same problem..
The proble here is the XML file is not able to locate the Schema file ...
I don't know what's happening...
Can u see whether the schema inclusion in xml is correct or not..
arun sharma
Greenhorn

Joined: Jul 02, 2003
Posts: 19
Hi Balaji;
I got the solution actually we have to set the Feature like this:
----------------------
"http://apache.org/xml/features/validation/schema",true
----------------------------------
then it works fine
anyway thanks for support...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why it is happening like this.........