On parse exceptions log warning and skip text
Change-Id: I4721aaa704c779a5bb295dc8f5085907342f8d57
diff --git a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
index 9888f2a..de32dcb 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
@@ -4,6 +4,7 @@
import org.w3c.dom.Element
import org.w3c.dom.NodeList
import org.xml.sax.InputSource
+import org.xml.sax.SAXParseException
import picocli.CommandLine
import picocli.CommandLine.*
import java.io.File
@@ -224,7 +225,12 @@
val inputStream: InputStream = zipFile.getInputStream(zipEntry)
val dbFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
val dBuilder: DocumentBuilder = dbFactory.newDocumentBuilder()
- val doc: Document = dBuilder.parse(InputSource(InputStreamReader(inputStream, "UTF-8")))
+ val doc: Document = try {
+ dBuilder.parse(InputSource(InputStreamReader(inputStream, "UTF-8")))
+ } catch (e: SAXParseException) {
+ LOGGER.warning("Error parsing file: " + zipEntry.name + " " + e.message)
+ return@forEach
+ }
doc.documentElement.normalize()
val docId: String = doc.documentElement.getAttribute("docid")