• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

xml validator problem

Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am doing a xml validation now. below is my code:
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
import javax.xml.parsers.*;
import java.io.File;
import java.io.FileInputStream;
public class validator {

public static void main(String[] args) {
try {
String xmlpath = "D:\\documents\\abc.xml";
File xmlf = new File(xmlpath);

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) {
String schemapath = "D:\\documents\\cde.xsd";
File schemaf = new File(schemapath);
try {
FileInputStream fis = new FileInputStream(schemaf);
return new InputSource(fis);
catch (Exception e) {return null;}
db.setErrorHandler(new DefaultHandler() {
public void error(SAXParseException e) throws SAXParseException { throw e; }
public void fatalError(SAXParseException e) throws SAXParseException { throw e; }
public void warning(SAXParseException e) throws SAXParseException {
System.out.println( e.toString() );

catch (Exception e) {


the xsd is correct. And the xml is valid i think. but when i run this program, it give me the following error.
org.xml.sax.SAXParseException: Valid documents must have a <!DOCTYPE declaration
org.xml.sax.SAXParseException: Element type "CollaborationProtocolProfile" is no
t declared.
at org.apache.crimson.parser.Parser2.error(Unknown Source)
at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at validator.main(validator.java:39)
for the first error, i don't know what it means.
for the second error, i have declared it in the schema, but why still said not defined?
can anybody shed some lite...
Posts: 11962
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you referencing your Schema document from the XML document?
Here's an example from w3schools.com:
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.This tutorial may also help u further.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!