Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javax.xml.parsers.ParserConfigurationException #16

Open
mfissehaye opened this issue Nov 2, 2016 · 4 comments
Open

javax.xml.parsers.ParserConfigurationException #16

mfissehaye opened this issue Nov 2, 2016 · 4 comments

Comments

@mfissehaye
Copy link

I tried to use the library according to the guideline on the GitHub page
The first problem I got is that there is no class called Book.

The fifth line of code in the Usage section tries to create a Book object from reader.readSection. I thought maybe you meant to say BookSection so I replaced it.

And further into the code reader.setFullContent(epubFilePath); throws the following exception. (I have put the complete stack trace)

What I understood while debugging is that the DocumentBuilderFactoryImpl class throws ParserConfigurationException if instance of DocumentBuilderFactoryImpl calls setFeature with names different from http://xml.org/sax/features/namespaces and http://xml.org/sax/features/validation

Is there a problem with my android depedencies?

javax.xml.parsers.ParserConfigurationException: http://apache.org/xml/features/nonvalidating/load-dtd-grammar
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:101)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.github.mertakdut.Reader.fillContent(Reader.java:98)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.github.mertakdut.Reader.setFullContent(Reader.java:39)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.a360ground.lomibooksrecycler.BookReaderActivity.onCreate(BookReaderActivity.java:31)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.Activity.performCreate(Activity.java:6178)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.access$900(ActivityThread.java:177)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.os.Looper.loop(Looper.java:135)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5910)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
@mertakdut
Copy link
Owner

mertakdut commented Nov 2, 2016

Hello,

  • Yes, i had a misstyping in usage section, corrected it now. Thank you.

  • I came across in unit tests, parsing some xml files was taking too long, because of the validations. So I disabled the validations (related answer). It works perfectly fine in my unit tests; but getting the same exceptions in Sample Application as well. Though it didn't occur to me that the exceptions breaks the operation of the library.

    I'll dig in for more info.

@mertakdut
Copy link
Owner

Android sdk (api-23) uses this method for setFeature:

`@Override
public void setFeature(String name, boolean value)
        throws ParserConfigurationException {
    if (name == null) {
        throw new NullPointerException("name == null");
    }

    if (NAMESPACES.equals(name)) {
        setNamespaceAware(value);
    } else if (VALIDATION.equals(name)) {
        setValidating(value);
    } else {
        throw new ParserConfigurationException(name);
    }
}`

As this states, android throws exception for all other features other than namespace and validation.

@lvs-coding
Copy link

lvs-coding commented Jan 6, 2017

Same problem here.
Get a ParserConfigurationException on reader.setFullContent(epubFilePath). The Exception doesn't break the operation and I can get the ebook content with bookSection.getSectionContent().

I'm getting the same error with the sample app provided EpubParser-Sample-Android-Application.

@lvs-coding
Copy link

lvs-coding commented Jan 6, 2017

It looks like Android SDK DocumentBuilderFactory cannot support these two features
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);

As these features are used for document validation maybe they are not mandatory ? anyway they are not supported on API 25.
docs here and here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants