W3CDom Helper fails to convert whenever some namespace declarations are missing
See original GitHub issueHello
I’ve been running into an issue where if I convert my Jsoup parsed document into a org.w3c.dom.Document with the W3CDom helper and that document happens to be missing namespace declarations we get the following exception:
NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
I’ve looked into this a bit and first thing I tried was using a locally forked version of the W3CDom helper that simply turned this flag off:
factory.setNamespaceAware(false);
However the issue continued, so instead I simply hacked the code to completely ignore namespaces
// (csueiras): We purposely remove any namespace because we get malformed HTML that might not be
// declaring all of it's namespaces!
Element el = doc.createElementNS("", sourceEl.tagName());
I am not completely sure if this will have any side effects, but it resolved the issues with the document I’m interacting with. I would be glad to provide a pull request if I have some guidance regarding how to properly handle this issue if it can be handled by Jsoup.
The document I’m having issues is simply making use of the Facebook like buttons using tags like this:
<fb:like ...
But there’s no namespace declaration for “fb”.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:11 (4 by maintainers)

Top Related StackOverflow Question
Actually I’m also stuck with this issue and there’s no
1.12.1version yet, but there’s a milestone for it. Don’t know when this version will be released but I hope it will be as soon as possible.Thanks, fixed