Win a copy of Functional Reactive Programming this week in the Other Languages 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 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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
arun sharma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic