my dog learned polymorphism*
The moose likes XML and Related Technologies and the fly likes xml validator problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml validator problem" Watch "xml validator problem" New topic
Author

xml validator problem

Howie Jiang
Greenhorn

Joined: Aug 25, 2003
Posts: 26
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();
dbf.setValidating(true);
dbf.setNamespaceAware(true);
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() );
}
});

db.parse(xmlf);
}
catch (Exception e) {
e.printStackTrace();
}


}

}
---------------------------------
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...
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Are you referencing your Schema document from the XML document?
Here's an example from w3schools.com:


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
.This tutorial may also help u further.


Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml validator problem
 
Similar Threads
it is urgent..please help me some one
schema validator
schema validator
validate xml dom with schema
Validate xml against schema