Akash Sudhakar created TIKA-2087:
------------------------------------

             Summary: Extracting text from xml file failing.
                 Key: TIKA-2087
                 URL: https://issues.apache.org/jira/browse/TIKA-2087
             Project: Tika
          Issue Type: Bug
          Components: core, parser
    Affects Versions: 1.13
            Reporter: Akash Sudhakar


While extracting text from file, we are getting 
org.apache.tika.exception.TikaException: XML parse error.

Code - 
FileInputStream inputStream = new FileInputStream(file);
    BodyContentHandler handler = new BodyContentHandler();
    AutoDetectParser parser = new AutoDetectParser();
    Metadata metadata = new Metadata();
    metadata.add(Metadata.CONTENT_ENCODING, Charset.defaultCharset().name());
    parser.parse(inputStream, handler, metadata);

Stack trace - 
Exception in thread "main" org.apache.tika.exception.TikaException: XML parse 
error
        at org.apache.tika.parser.xml.XMLParser.parse(XMLParser.java:78)
        at 
org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:280)
        at 
org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:280)
        at 
org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:120)
        at 
org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:136)
        at com.test.TestClass1.main(TestClass1.java:24)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 28; The 
reference to entity "A" must end with the ';' delimiter.
        at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
        at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
        at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
        at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
        at 
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1465)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1844)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3058)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
        at 
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:504)
        at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
        at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
        at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at 
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
        at 
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
        at org.apache.tika.parser.xml.XMLParser.parse(XMLParser.java:72)
        ... 5 more

Error is due to '&' character present in xml file.

Is there a way we can override or correct this exception in tika by setting 
some property.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to