Marko Asplund wrote:
i've found for ignoring certain errors is to classify errors based on
string matching on SAXParseException's message text. string matching is
error prone and is IMO not the best way to classify errors. it would be
nice if Xerces would specify integer error codes for each parse error and
provide a way of getting this code when an error occurs. one way to do
this would be to add an
int getErrorCode()
method to SAXParseException.
We will *not* be modifying standard APIs for use within
Xerces. However, you can work around the problem if you
use the Xerces interfaces and classes. Here's an example:
# File: MyConfig.java
import java.util.Locale;
import org.apache.xerces.impl.XMLErrorReporter;
import org.apache.xerces.parsers.StandardParserConfiguration;
import org.apache.xerces.util.MessageFormatter;
public class MyConfig
extends StandardParserConfiguration
implements MessageFormatter {
public static final String DOMAIN = "MyDomain"
public MyConfig() {
fErrorHandler.putMessageFormatter(DOMAIN, this);
}
public String formatMessage(Locale locale,
String key, Object[] args) {
StringBuffer str = new StringBuffer();
str.append(key);
int length = args != null ? args.length : 0;
for (int i = 0; i < length; i++) {
str.append('\t');
str.append(String.valueOf(args[i]));
}
return str.toString();
}
protected XMLErrorReporter createErrorReporter() {
return MyErrorReporter();
}
}
# File: MyErrorReporter.java
import org.apache.xerces.impl.XMLErrorReporter;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XNIException;
public class MyErrorReporter
extends XMLErrorReporter {
public void reportError(XMLLocator location,
String domain, String key, Object[] args,
short severity) throws XNIException {
super.reportError(location,
MyConfig.DOMAIN, domain+'#'+key, args,
severity);
}
}
You're still returned a string but it doesn't have
the problem with localization, etc. And this way you
still access to the original "code" of the error which
is a domain and a key as well as the arguments that are
used for the replacement text.
Now to use this new configuration to parse SAX documents,
do the following:
// import org.apache.xerces.parsers.SAXParser;
// import org.xml.sax.XMLReader;
XMLReader parser = new SAXParser(new MyConfig());
Would this solve your problem?
NOTE: I haven't checked this code for typos.
--
Andy Clark * [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]