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

JDOM 2.x vs 1.x compatibility problem when parsing DOM documents #138

rolfl opened this Issue Nov 5, 2014 · 0 comments


None yet
1 participant

rolfl commented Nov 5, 2014

JDOM 2.x handles namespace aware documents well, but documents created manually, in a non-aware way, and then parsed by DOM builder, do not produce the 'right' results in JDOM 2.x even though JDOM 1.x produces the correct output.

See Stack Overflow - How to prevent XMLOutputter in JDOM2 from cutting attribute name (namespace-part)?

This is not to say that JDOM 2.x is doing the wrong thing, just that JDOM 1.x handles poorly-created DOM input better than JDOM 2.x.

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    org.w3c.dom.Document doc = dbFactory.newDocumentBuilder().newDocument();

    Element root = doc.createElement("Document");

    root.setAttribute("xmlns", "urn:iso:foo");
    root.setAttribute("xmlns:xsi", "");
    root.setAttribute("xsi:schemaLocation", "urn:iso:foo bar.xsd");

The above code, when processed by JDOM 1.x DOMBuilder, produces:

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:foo" xmlns:xsi="" xsi:schemaLocation="urn:iso:foo bar.xsd" />

but when processed by JDOM 2.x it produces:

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:foo" xmlns:xsi="" schemaLocation="urn:iso:foo bar.xsd" />

(note the missing xsi: prefix).

If the DOM document is built with:

    root.setAttribute("xmlns", "urn:iso:foo");
    root.setAttributeNS("", "xmlns:xsi", "");
    root.setAttributeNS("", "xsi:schemaLocation", "urn:iso:foo bar.xsd");

then it works as expected

@rolfl rolfl added the Target 2.0.x label Feb 13, 2015

rolfl added a commit that referenced this issue Feb 15, 2015

Fixes #138 - backward ccompatibility issue with JDOM 1.x DOM
JDOM 1.x managed to handle badly-built DOM documents that had implied
namespaces in place.

@rolfl rolfl closed this in ae05d54 Feb 15, 2015

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