8000 Configure XML#builder() to use setValidating or setSchema or none · Issue #116 · jenetics/jpx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Configure XML#builder() to use setValidating or setSchema or none #116

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

Closed
avianey opened this issue Jan 9, 2020 · 3 comments
Closed

Configure XML#builder() to use setValidating or setSchema or none #116

avianey opened this issue Jan 9, 2020 · 3 comments
Assignees
Milestone

Comments

@avianey
Copy link
Contributor
avianey commented Jan 9, 2020

For now it calls factory.setValidating(true); which is inappropriate in some use case :

  • offline / schema URL not reachable
  • Android ecosystem where validation throw error

Would be great to be able to configure the behaviour for factory.newDocumentBuilder()

@avianey
Copy link
Contributor Author
avianey commented Jan 9, 2020

since there's only two usage for DocumentBuilderFactory.newInstance() we could :

  • use a kind of DocumentBuilderFactoryInstanceProvider
  • or use DocumentBuilderFactory#newInstance(String factoryClassName, ClassLoader classLoader)

Any preference for a pull request ? (later one is only supported since 1.6)

@jenetics
Copy link
Owner
jenetics commented Jan 9, 2020

Since there are several places where I have to created XML related classes, the more general solution of a SPI would be desirable.

package io.jenetics.jpx;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;

public abstract class XMLProvider {
    protected XMLProvider() {
    }
    // Used for reading files.
    public XMLInputFactory xmlInputFactory() {
        return XMLInputFactory.newInstance();
    }
    // Used for writing files.
    public XMLOutputFactory xmlOutputFactory() {
        return XMLOutputFactory.newInstance();
    }
    // Used for creating GPX extensions documents.
    public DocumentBuilderFactory documentBuilderFactory() {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(true);
        factory.setIgnoringElementContentWhitespace(true);
        factory.setNamespaceAware(true);
        return factory;
    }
    public static XMLProvider provider() {
        // Do service lookup and return default impl if nothing is found.
        return null;
    }
}

I think this could solve the XML problems once and for all ;-)

@jenetics
Copy link
Owner

Merged into r1.7.0 branch.

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

No branches or pull requests

2 participants
0