Hello
I tried to use the org.apache.xerces.parsers.DOMParser to parse an xml file.
I tried it on the personal-schema.xml that can be found in the same zip file with the parser itself.
Constantly, I got parse errors.
I used this xerces version:
<xml-xerces_20010305130204.tar.gz>
I put the xml and the xsd files in the same path from which I ran the program.
I use java version 1.3
this is my java code:
package dom;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xerces.parsers.*;
public class MyClass1 implements ErrorHandler {
public MyClass1(String file) {
try {
org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
parser.setFeature( "http://xml.org/sax/features/validation",true);
parser.setErrorHandler(this);
parser.parse(file);
System.out.println(parser.getDocument());
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new MyClass1(args[0]);
}
//
// ErrorHandler methods
//
/** Warning. */
public void warning(SAXParseException ex) {
System.err.println("[Warning] "+
getLocationString(ex)+": "+
ex.getMessage());
}
/** Error. */
public void error(SAXParseException ex) {
System.err.println("[Error] "+
getLocationString(ex)+": "+
ex.getMessage());
}
/** Fatal error. */
public void fatalError(SAXParseException ex) throws SAXException {
System.err.println("[Fatal Error] "+
getLocationString(ex)+": "+
ex.getMessage());
throw ex;
}
/** Returns a string of the location. */
private String getLocationString(SAXParseException ex) {
StringBuffer str = new StringBuffer();
String systemId = ex.getSystemId();
if (systemId != null) {
int index = systemId.lastIndexOf('/');
if (index != -1)
systemId = systemId.substring(index + 1);
str.append(systemId);
}
str.append(':');
str.append(ex.getLineNumber());
str.append(':');
str.append(ex.getColumnNumber());
return str.toString();
}
}
