I'm using jackson-dataformat-csv to read a csv file in, and I'm getting a NoSuchMethodError when trying to parse the mappingIterator with the line
MyRecord record = (MyRecord) it.nextValue();
of this snipped (slightly modified, ex handling removed)
CsvMapper csvMapper = new CsvMapper();
CsvSchema schema = csvMapper.schemaFor(MyRecord.class);
#SuppressWarnings("rawtypes")
MappingIterator<Entry> it = csvMapper.reader(MyRecord.class)
.with(schema).readValues(filename);
List<MyRecord> records = new ArrayList<>();
while (it.hasNextValue()) {
MyRecord record = (MyRecord) it.nextValue();
records.add(record);
}
https://github.com/FasterXML/jackson-dataformat-csv/issues/49
My issue is very close to this one, except I've already tried the solution of making sure jackson-core, jackson-databind, jackson-dataformat-csv, and jackson-annotations are all the same version (2.8). It looks like there is a 2.9 that changes things now, but at my company I don't have access to 2.9. Is there some other package I could have a conflict in?
error:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.util.BufferRecycler.allocCharBuffer(II)[C
at com.fasterxml.jackson.dataformat.csv.impl.TextBuffer.findBuffer(TextBuffer.java:160)
at com.fasterxml.jackson.dataformat.csv.impl.TextBuffer.emptyAndGetCurrentSegment(TextBuffer.java:404)
at com.fasterxml.jackson.dataformat.csv.impl.CsvDecoder.nextString(CsvDecoder.java:607)
at com.fasterxml.jackson.dataformat.csv.CsvParser._handleNextEntry(CsvParser.java:678)
at com.fasterxml.jackson.dataformat.csv.CsvParser.nextToken(CsvParser.java:523)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:189)
This has been solved, although I'm still not sure about the root cause. I believe the root cause may be specific to my own use case (my company uses it's own in-house systems for local development workspaces as well as dependency management. I ended up creating a new local (and eclipse) workspace and this same code seems to be working fine now.
Related
I wish to convert a .XPS File to Text with Java or Kotlin.
Aspose is to expensive for me.
I found Java-AXP, which should do the job but I did not find any documentation or sample code for it.
I managed to get the Java-AXP Core to my project libraries in IntelliJ. I can now access the files from within my project. But actually understanding how to use the library to get the text converstion is way beyond me.
The only attempt to use the library with example code I found here:
File b =new File("D:\\Chemia\\Clients\\Clients\\Docs\\Equipment\\CCP\\XPSOCRDemo.xps");
IXPSAccess access = new XPSFileAccessImpl(b);
IXPSFileAccess xpsFileAccess = access.getFileAccess();
XPSDocumentAccessImpl xpsimpl=new XPSDocumentAccessImpl(access);
int docunum = xpsimpl.getFirstDocNum();
IDocumentStructure structure=xpsimpl.getDocumentStructure(docunum);
List<IOutlineEntry> list=(List<IOutlineEntry>)
structure.getDocumentStructureOutline().getDocumentOutline().getOutlineEntry(
);
list.stream().forEach(restu->{
System.out.println( restu.getOutlineTarget());
});
However, I do get the same null pointer exeption as the OP and I can't fix it. I'd need a working example code to continue on my own.
So how can I use Java-AXP? Or are there alternative libraries? I am open to use anything.
Thanks for any help.
Edit:
#Abra Thanks.
Exception in thread "main" java.lang.IllegalStateException: structure must not be null
at MainKt.main(main.kt:80)
at MainKt.main(main.kt)
73 | val structure = xpsimpl.getDocumentStructure(0)
80 | val list = structure.documentStructureOutline?.documentOutline?.outlineEntry as List<IOutlineEntry>?
xpsimpl.getDocumentStructure(docunum) is null
I can not use a website for my purpose because the XPS files contain sensitive information.
Edit: Here is the solution I found.
I found this repo which uses Java-AXP. However there seemed to be some differences to the java-axp-core.jar I used from
Google Code
So I copied the javaaxp folder to my project.
It needed Apache Tika so I downloaded tika-app-2.1.0.jar from Apache Tika and included it in my project via the Project Structure menu.
In XPSZipFileAccess.java I had a wrong import for IOUtils so I changed
import org.apache.tika.io.IOUtils;
to
import org.apache.commons.io.IOUtils;
Now the Java-AXP could resolve all references.
Then I copied XPSParser.java to the root of my project and made sure all imports work.
In DocSaver.java on line 90 I found where XPSParser was used and I adapted the code so I could convert the XPS file to text:
val xpsFile = File(path + "filename.xps")
val inputStream = FileInputStream(xpsFile)
val metadata = Metadata()
val handler = BodyContentHandler()
XPSParser().parse(inputStream, handler, metadata, ParseContext())
val docContents = handler.toString()
println(docContents)
inputStream.close()
Hope it helps someone.
Here is the solution I found.
I found this repo which uses Java-AXP. However there seemed to be some differences to the java-axp-core.jar I used from
Google Code
So I copied the javaaxp folder to my project.
It needed Apache Tika so I downloaded tika-app-2.1.0.jar from Apache Tika and included it in my project via the Project Structure menu.
In XPSZipFileAccess.java I had a wrong import for IOUtils so I changed
import org.apache.tika.io.IOUtils;
to
import org.apache.commons.io.IOUtils;
Now the Java-AXP could resolve all references.
Then I copied XPSParser.java to the root of my project and made sure all imports work.
In DocSaver.java on line 90 I found where XPSParser was used and I adapted the code so I could convert the XPS file to text:
val xpsFile = File(path + "filename.xps")
val inputStream = FileInputStream(xpsFile)
val metadata = Metadata()
val handler = BodyContentHandler()
XPSParser().parse(inputStream, handler, metadata, ParseContext())
val docContents = handler.toString()
println(docContents)
inputStream.close()
Using the following library
<dependency>
<groupId>net.rcarz</groupId>
<artifactId>jira-client</artifactId>
<version>0.5</version>
</dependency>
I am getting error while executing below code:
BasicCredentials creds = new BasicCredentials("username", "password");
JiraClient jira = new JiraClient("xyz/rest/api/2/issue", creds);
Issue newIssue = jira.createIssue("XYZ", "Bug")
.field(Field.SUMMARY, "tEST bUG")
.field("customfield_20200","No STeps")
.field("customfield_20202","No actual")
.field("customfield_25600",Field.valueById("35650"))
.execute();
Getting error for field("customfield_25600",Field.valueByID("35650"))
Error Description :
java.lang.UnsupportedOperationException: option is not a supported
field type
This is customized field in JIRA.
Please let me know if required more information.
Thanks in advance.
Field#toJson() method had not know about option type in v0.5, it was added later. That is why method throws UnsupportedOperationException. Try to use the latest version from GitHub: https://github.com/rcarz/jira-client
Seems to be a known issue with the library,the field you try to add is probably an option and it is not supported
The error was already reported here:
https://github.com/rcarz/jira-client/issues/123
Hi,
trying to use custom fields, I encounter the following issue :
For a "Select List (single choice)" type of field, I get the following exception when trying to create an issue :
Exception: java.lang.UnsupportedOperationException: option is not a supported field type
at net.rcarz.jiraclient.Field.toJson(Field.java:655)
at net.rcarz.jiraclient.Issue$FluentCreate.executeCreate(Issue.java:104)
at net.rcarz.jiraclient.Issue$FluentCreate.execute(Issue.java:59)
I'm using JIRA v7.1.0-OD-05-006
It seems to have to do with the JIRA version.
Following the link to #154, it seems that it was not fixed.
https://github.com/rcarz/jira-client/pull/154
The issue still persists
Caused by: java.lang.UnsupportedOperationException: option is not a supported field type
at net.rcarz.jiraclient.Field.toJson(Field.java:737)
at net.rcarz.jiraclient.Issue$FluentCreate.executeCreate(Issue.java:102)
at net.rcarz.jiraclient.Issue$FluentCreate.execute(Issue.java:57)
Here is my snippet code looks like. The customfield_12133 is an options.
JiraClient jiraClient;
Issue issue = jiraClient.createIssue("MYPROJECT", "Internal Bug")
.field(Field.SUMMARY, summary)
.field(Field.DESCRIPTION, summary)
.field("customfield_12133", "Other")
.execute();
Finally pull #176 should actually have fixed it:
https://github.com/rcarz/jira-client/pull/176
might be fixed in the next version (0.6) of the library
I am doing a unit testing which includes parsing of data with XStream parser.I used Mockito for mocking context.But the test case fails with an error log:
java.lang.RuntimeException: Method newInstance in org.xmlpull.v1.XmlPullParserFactory not mocked. See http://g.co/androidstudio/not-mocked for details.
at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java)
at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:57)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1049)
at com.att.apis.metadata.MetadataHandler.execute(MetadataHandler.java:38)
at com.att.apis.services.ServerOperations.executePostOperation(ServerOperations.java:20)
at com.att.framework.helper.request.MetadataAPIHandler.executeAPIRequest(MetadataAPIHandler.java:58)
at com.att.framework.helper.request.MetadataAPIHandlerMokitoTest.executeAPIRequest(MetadataAPIHandlerMokitoTest.java:57)
The error is happening at the line " response = (MetadataResponse)xs.fromXML(iStream); " in the below code block
InputStream iStream = responseData.getInputStream();
XStream xs = new XStream();
xs.autodetectAnnotations(true);
xs.alias("helloa", A.class);
xs.alias("hellob", B.class);
xs.alias("helloc",C.class);
response = (MetadataResponse)xs.fromXML(iStream);
As per the answer from Android: XmlPullParserFactory.newInstance() creating a null factory, I added
testOptions {
unitTests.returnDefaultValues = true
}
in build.gradle.
After the update when NullPointer Exception with below log occurred.
java.lang.NullPointerException
at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:59)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1049)
at com.att.apis.metadata.MetadataHandler.execute(MetadataHandler.java:38)
at com.att.apis.services.ServerOperations.executePostOperation(ServerOperations.java:20)
at com.att.framework.helper.request.MetadataAPIHandler.executeAPIRequest(MetadataAPIHandler.java:58)
at com.att.framework.helper.request.MetadataAPIHandlerMokitoTest.executeAPIRequest(MetadataAPIHandlerMokitoTest.java:57)
Can anyone help me to sort out the issue
If you think that mocking XmlPullParser is not a good idea and you would rather write tests against the real parser, so you can check whether real XML documents are actually parsed correctly by your code, this is how you can solve it:
Simply add this xmlpull dependency to your app's gradle file:
testImplementation group: 'xmlpull', name: 'xmlpull', version: '1.1.3.1'
It will be used only for running the unit tests and will not be packaged in your APK
XmlPullParserFactory comes from the Android platform and therefore can not be mocked in the unit tests as they are executed with the Java VM you have installed on your computer.
You may want to use the Robolectric framework, it allows for the unit tests to make calls to the Android platform (it mocks almost everything in the whole platform)
You should refactor your code a bit and mock Xstream and all it's dependencies. For example you can externalize creation of Xstream and pass it to your method under test.
Xstream mockXstream = Mockito.mock(Xstream.class);
//mock all xstream method calls
void myMethodUnderTest(Xstream xs){
InputStream iStream = responseData.getInputStream();
xs.autodetectAnnotations(true);
xs.alias("helloa", A.class);
xs.alias("hellob", B.class);
xs.alias("helloc",C.class);
response = (MetadataResponse)xs.fromXML(iStream);
}
I have a quite big (>2.5 GB) h2 database file. Driver version is 1.4.182. Everything worked fine but recently the DB stop to work with exception:
Błąd ogólny: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-182] HY000/50000 (Help)
org.h2.jdbc.JdbcSQLException: Błąd ogólny: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-182]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.DbException.convert(DbException.java:295)
at org.h2.engine.Database.openDatabase(Database.java:297)
at org.h2.engine.Database.<init>(Database.java:260)
at org.h2.engine.Engine.openSession(Engine.java:60)
at org.h2.engine.Engine.openSession(Engine.java:167)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:145)
at org.h2.engine.Engine.createSession(Engine.java:128)
at org.h2.engine.Engine.createSession(Engine.java:26)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:347)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:92)
at org.h2.Driver.connect(Driver.java:72)
at org.h2.server.web.WebServer.getConnection(WebServer.java:750)
at org.h2.server.web.WebApp.test(WebApp.java:895)
at org.h2.server.web.WebApp.process(WebApp.java:221)
at org.h2.server.web.WebApp.processRequest(WebApp.java:170)
at org.h2.server.web.WebThread.process(WebThread.java:137)
at org.h2.server.web.WebThread.run(WebThread.java:93)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at org.h2.mvstore.db.ValueDataType.compare(ValueDataType.java:102)
at org.h2.mvstore.MVMap.compare(MVMap.java:741)
at org.h2.mvstore.Page.binarySearch(Page.java:388)
at org.h2.mvstore.MVMap.put(MVMap.java:179)
at org.h2.mvstore.MVMap.put(MVMap.java:133)
at org.h2.mvstore.db.TransactionStore.rollbackTo(TransactionStore.java:491)
at org.h2.mvstore.db.TransactionStore$Transaction.rollback(TransactionStore.java:785)
at org.h2.mvstore.db.MVTableEngine$Store.initTransactions(MVTableEngine.java:223)
at org.h2.engine.Database.open(Database.java:736)
at org.h2.engine.Database.openDatabase(Database.java:266)
... 17 more
The problem occurs in my application and using H2 web frontend.
I have tried solution from similar question but I cannot downgrade H2 to 1.3.x as it cannot read 1.4.x DB files.
My questions are:
How to handle it? Is it to possible to make it work again? I have tried downgrade H2 to 1.4.177 but it didn't help.
Is there any way to at least recover data to other format? I could use other DB (Sqlite, etc.) however I would need a way to get to these data.
EDIT: updated stacktrace
EDIT 2: Result of using Recovery tool:
$ java -cp h2-1.4.182.jar org.h2.tools.Recover
Exception in thread "main" java.lang.IllegalStateException: Unknown tag 50 [1.4.182/6]
at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:762)
at org.h2.mvstore.type.ObjectDataType.read(ObjectDataType.java:222)
at org.h2.mvstore.db.TransactionStore$ArrayType.read(TransactionStore.java:1792)
at org.h2.mvstore.db.TransactionStore$ArrayType.read(TransactionStore.java:1759)
at org.h2.mvstore.Page.read(Page.java:843)
at org.h2.mvstore.Page.read(Page.java:230)
at org.h2.mvstore.MVStore.readPage(MVStore.java:1813)
at org.h2.mvstore.MVMap.readPage(MVMap.java:769)
at org.h2.mvstore.Page.getChildPage(Page.java:252)
at org.h2.mvstore.MVMap.getFirstLast(MVMap.java:351)
at org.h2.mvstore.MVMap.firstKey(MVMap.java:218)
at org.h2.mvstore.db.TransactionStore.init(TransactionStore.java:169)
at org.h2.mvstore.db.TransactionStore.<init>(TransactionStore.java:117)
at org.h2.mvstore.db.TransactionStore.<init>(TransactionStore.java:81)
at org.h2.tools.Recover.dumpMVStoreFile(Recover.java:593)
at org.h2.tools.Recover.process(Recover.java:331)
at org.h2.tools.Recover.runTool(Recover.java:192)
at org.h2.tools.Recover.main(Recover.java:155)
I also noticed that two another files (.txt and .sql) has been created but they don't seem to contain a data.
I got the same situation last week with JIRA database, it took me few hours to do google regarding to this problem however, there are no answers which can resolve the situation.
I decided to take a look at H2 source code and I can recover the whole database with very simple code. I may not understand whole picture about the situation e.g. root cause, in which condition it happened, etc.
However, the cause is: when you connect to h2 file then H2 engine will look into auditLog and rollback the in-progress transactions, there are some data which have unknown type (id is 17) and H2 fails to rollback due to exception during recognize the type (id 17).
My code is simple, add h2 lib into your build path then just manual connect to file and clear auditLog because I think it is just the log and will not have big impact (someone may correct me).
Hopefully, you can resolve your problem as well.
public static void main(final String[] args) {
// open the store (in-memory if fileName is null)
final MVStore store = MVStore.open("C:\\temp\\h2db.mv.db");
final MVMap<Object, Object> openMap = store.openMap("undoLog");
openMap.clear();
// close the store (this will persist changes)
store.close();
}
Another solution for this problem:
Go to your home folder (~ in linux).
Move all files named [*.mv.db] to a backup with a different name. For example: mv xyz.mv.db xyz.mv.db.backup
Restart your database.
This seems to clear out MVStore meta-data used for H2 undo features, and resolves the NPE from the MV Store compare.
I had a similar problem:
[HY000][50000] Allgemeiner Fehler: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-176]
java.lang.NullPointerException
I tried to connect with IntelliJ to H2 file DB. H2 driver version was 1.3.176 but the DB file version had 1.3.161. So downgraded the driver to 1.3.161 in IntelliJ solved the problem completely.
I'm trying to validate an Atom feed with Java 5 (JRE 1.5.0 update 11). The code I have works without problem in Java 6, but fails when running in Java 5 with a
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xml:base' to a(n) 'attribute declaration' component.
I think I remember reading something about the version of Xerces bundled with Java 5 having some problems with some schemas, but i cant find the workaround. Is it a known problem ? Do I have some error in my code ?
public static void validate() throws SAXException, IOException {
List<Source> schemas = new ArrayList<Source>();
schemas.add(new StreamSource(AtomValidator.class.getResourceAsStream("/atom.xsd")));
schemas.add(new StreamSource(AtomValidator.class.getResourceAsStream("/dc.xsd")));
// Lookup a factory for the W3C XML Schema language
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
// Compile the schemas.
Schema schema = factory.newSchema(schemas.toArray(new Source[schemas.size()]));
Validator validator = schema.newValidator();
// load the file to validate
Source source = new StreamSource(AtomValidator.class.getResourceAsStream("/sample-feed.xml"));
// check the document
validator.validate(source);
}
Update : I tried the method below, but I still have the same problem if I use Xerces 2.9.0. I also tried adding xml.xsd to the list of schemas (as xml:base is defined in xml.xsd) but this time I have
Exception in thread "main" org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Update 2: I tried to configure a proxy with the VM arguments -Dhttp.proxyHost=<proxy.host.com> -Dhttp.proxyPort=8080 and now it works. I'll try to post a "real answer" from home.
and sorry, I cant reply as a comment : because of security reasons XHR is disabled from work ...
Indeed, people have been mentioning the Java 5 Sun provided SchemaFactory is giving troubles.
So: did you include Xerces in your project yourself?
After including Xerces, you need to ensure it is being used. If you like to hardcode it (well, as a minimal requirement you'd probably use some application properties file to enable and populate the following code):
String schemaFactoryProperty =
"javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI;
System.setProperty(schemaFactoryProperty,
"org.apache.xerces.jaxp.validation.XMLSchemaFactory");
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Or, if you don't want to hardcode, or when your troublesome code would be in some 3rd party library that you cannot change, set it on the java command line or environment options. For example (on one line of course):
set JAVA_OPTS =
"-Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema
=org.apache.xerces.jaxp.validation.XMLSchemaFactory"
By the way: apart from the Sun included SchemaFactory implementation giving trouble (something like com.sun.org.apache.xerces.internal.jaxp.validation.xs.schemaFactoryImpl), it also seems that the "discovery" of non-JDK implementations fails in that version. If I understand correctly than, normally, just including Xerces would in fact make SchemaFactory#newInstance find that included library, and give it precedence over the Sun implementation. To my knowledge, that fails as well in Java 5, making the above configuration required.
I tried to configure a proxy with the VM arguments -Dhttp.proxyHost=<proxy.host.com> -Dhttp.proxyPort=8080 and now it works.
Ah, I didn't realize that xml.xsd is in fact the one referenced as http://www.w3.org/2001/xml.xsd or something like that. That should teach us to always show some XML and XSD fragments as well. ;-)
So, am I correct to assume that 1.) to fix the Java 5 issue, you still needed to include Xerces and set the system property, and that 2.) you did not have xml.xsd available locally?
Before you found your solution, did you happen to try using getResource rather than getResourceAsStream, to see if the exception would then have showed you some more details?
If you actually did have xml.xsd available (so: if getResource did in fact yield a URL) then I wonder what Xerces was trying to fetch from the internet then. Or maybe you did not add that schema to the list prior to adding your own schemas? The order is important: dependencies must be added first.
For whoever gets tot his question using the search: maybe using a custom EntityResolver could have indicated the source of the problem as well (if only writing something to the log and just returning null to tell Xerces to use the default behavior).
Hmmm, just read your "comment" -- editing does not alert people for new replies, so time to ask your boss for some iPhone or some other gadget that is connected to the net directly ;-)
Well, I assume you added:
schemas.add(
new StreamSource(AtomValidator.class.getResourceAsStream("/xml.xsd")));
If so, is xml.xsd actually to be found on the classpath then? I wonder if the getResourceAsStream did not yield null in your case, and how new StreamSource(null) would act then.
Even if getResourceAsStream did not yield null, the resulting StreamSource would still not know where it was loaded from, which may be a problem when trying to include references. So, what if you use the constructor StreamSource(String systemId) instead:
schemas.add(new StreamSource(AtomValidator.class.getResource("/atom.xsd")));
schemas.add(new StreamSource(AtomValidator.class.getResource("/dc.xsd")));
You might also use StreamSource(InputStream inputStream, String systemId), but I don't see any advantage over the above two lines. However, the documentation explains why passing the systemId in either of the 2 constructors seems good:
This constructor allows the systemID to be set in addition to the input stream, which allows relative URIs to be processed.
Likewise, setSystemId(String systemId) explains a bit:
The system identifier is optional if there is a byte stream or a character stream, but it is still useful to provide one, since the application can use it to resolve relative URIs and can include it in error messages and warnings (the parser will attempt to open a connection to the URI only if there is no byte stream or character stream specified).
If this doesn't work out, then maybe some custom error handler can give you more details:
ErrorHandlerImpl errorHandler = new ErrorHandlerImpl();
validator.setErrorHandler(errorHandler);
:
:
validator.validate(source);
if(errorHandler.hasErrors()){
LOG.error(errorHandler.getMessages());
throw new [..];
}
if(errorHandler.hasWarnings()){
LOG.warn(errorHandler.getMessages());
}
...using the following ErrorHandler to capture the validation errors and continue parsing as far as possible:
import org.xml.sax.helpers.DefaultHandler;
private class ErrorHandlerImpl extends DefaultHandler{
private String messages = "";
private boolean validationError = false;
private boolean validationWarning = false;
public void error(SAXParseException exception) throws SAXException{
messages += "Error: " + exception.getMessage() + "\n";
validationError = true;
}
public void fatalError(SAXParseException exception) throws SAXException{
messages += "Fatal: " + exception.getMessage();
validationError = true;
}
public void warning(SAXParseException exception) throws SAXException{
messages += "Warn: " + exception.getMessage();
validationWarning = true;
}
public boolean hasErrors(){
return validationError;
}
public boolean hasWarnings(){
return validationWarning;
}
public String getMessages(){
return messages;
}
}