You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Jerzy Puchala <je...@scdi.com> on 2000/07/21 16:05:51 UTC
Who I did validation (was: Errata...) [long]
First I just started play with Xerces parser.
Like I wrote in previous letter this version is NOT working with 1.1.2
version of Xercers.
There I will include part of code which is working on my machine.
<MAJOR PROGRAM CLASS>
import com.sun.javadoc.*;
import java.util.Collection;
import java.io.IOException;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.SAXException;
public class MyClass2 {
public static void main(String arg[]) throws Exception {
MyClass2 myClass = new MyClass2(arg[0]);
}
public MyClass2(String a){
getWork(a);
}
private void getWork(String DDuri) {
try {
DOMParser parser = new DOMParser();
try {
parser.setErrorHandler(new MyErrorHandler());
parser.setFeature("http://apache.org/xml/features/allow-java-encodings",
true);
parser.setFeature("http://xml.org/sax/features/validation",
true);
parser.parse(DDuri);
Document doc = parser.getDocument();
//here do something with your document, this is not subject of this
//post
}
catch (SAXException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
</MAJOR PROGRAM CLASS>
<MyErrorHandler clas>
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
public class MyErrorHandler implements ErrorHandler {
/** 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();
} // getLocationString(SAXParseException):String
}
</MyErrorHandler class>
In additon exact look of line with encoding in my xml is:
<?xml version="1.0" encoding="Cp1252"?>
This line is generated by Deployment Descriptor Editor from Inprise
Application Server, adn I can not send whole one. But this was line
which was responsible for error.
I do not made any mapings and changing in any files. I work on Windows
NT 40 Workstation. I have jdk1.2.2_6.
I have to cut big part of my program from this letter but I belive
that I do not cat out to much.
Once again I am not work with Xerces long time, and maby this problem
can be solved better way. In addition if there are any lines in the
code which are no nessesery - I am sorry (a specialy in import can be
be too much).
I hope that whis will help somebody. Sorry for my poor english.
Jerzy Puchala
--
+--------------------------------+
| Jerzy Puchala |
+--------------------------------+
| jerzypuc@scdi.com |
+--------------------------------+