question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

W3CDom Helper fails to convert whenever some namespace declarations are missing

See original GitHub issue

Hello

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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Freezystemcommented, Jul 25, 2018

Actually I’m also stuck with this issue and there’s no 1.12.1 version 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.

1reaction
jhycommented, Apr 29, 2018

Thanks, fixed

Read more comments on GitHub >

github_iconTop Results From Across the Web

The package org.w3c.dom is accessible from more than one ...
I wanted to migrate a project from Java 8 to Java 11. A few library issues. Easy to fix. But on this one,....
Read more >
Namespace declarations are lost on transformation ... - Apache
When I read this document as a StreamSource or SAXSource and transform it with Xalan into a DOMResult, the namespaces are invalid because ......
Read more >
eternal problem: NAMESPACE_ERR - Oracle Communities
Basically, I want to import namespace'd nodes into a new DOM structure, and I get the usual error: Exception in thread "main" org.w3c.dom....
Read more >
JAXB Users Guide - Java EE
This document explains various interesting/complex/tricky aspects of JAXB, based on questions posted on the JAXB users forum and answers I provided.
Read more >
Contents - lxml
Why do I get errors about missing UCS4 symbols when installing lxml? ... tag declarations of a namespace into one Python module and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found