ninjaxelite
ninjaxelite

Reputation: 1178

SAXParser not parsing xml with 8001 characters

I have an xml string with 8001 chars that I want to parse with SAXParser but I get the exception below. If I remove or add just one character to the xml, everything works perfectly. The xml is loaded from clob field in oracle DB.

The Exception: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 39; Content ist nicht zulässig in Prolog.

Can anyone explain me why this happens?

public static boolean isWellformed(final String xml) {
        if (xml == null) {
            return false;
        }

        SAXParser saxParser;
        DefaultHandler dh;
        try {
            final SAXParserFactory spfactory = SAXParserFactory.newInstance();
            saxParser = spfactory.newSAXParser();
            dh = new DefaultHandler();
        } catch (final Exception ex) {
            log.error("Cannot initialize SAX parser.", ex);
            return false;
        }

        ByteArrayInputStream bin = null;

        try {
            bin = new ByteArrayInputStream(xml.getBytes("UTF-8"));
            saxParser.parse(bin, dh);
        } catch (final SAXException se) {
            return false;
        } catch (final IOException ex) {
            return false;
        } finally {
            IOUtils.close(bin);
        }
        return true;
    }

The XML is generated and used by CKEditor. XML sample:

<?xml version="1.0" encoding="UTF-8"?><segment><chapter level="2" align=" center">Decisions</chapter><text>Text text  text .....</text></segment>

Upvotes: 0

Views: 79

Answers (0)

Related Questions