You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So basically I noticed this crash when trying to use w3CDom.asString() for a site which was created using Vue.js, and it was using "v-bind" in the place of "xxx"
To reproduce you can run the following test case:
@Test
void testNameSpaceCrash()
{
final W3CDom w3CDom = new W3CDom().namespaceAware(false);
final String html = """
<html>
<body>
<div xxx:class="test"></div>
</body>
</html>""";
final Document jSoupDoc = Jsoup.parse(html);
final org.w3c.dom.Document w3CDoc = w3CDom.fromJsoup(jSoupDoc);
assertDoesNotThrow(() -> w3CDom.asString(w3CDoc));
}
The text was updated successfully, but these errors were encountered:
I'm not sure what the best way to handle this is. The exception is coming out of the JDKs XML serializer (com.sun.org.apache.xml.internal.serializer) and it's always going to throw an exception if an attribute has an undeclared prefix.
A couple of options:
When creating the attribute, jsoup could set an arbitrary namespace URI for an undeclared prefix. The output would be something like: <div xmlns:xxx="undefined" xxx:class="test"></div>
Or, we could escape the : in the attribute key and so the output would be: <div xxxU00003Aclass="test"></div>
Option 1 is probably more compatible (in that in this instance of Vue, the JS would still execute).
Can you add some detail to your use case -- what are you trying to do with using this W3C interface and serialization vs the jsoup document serialization?
jhy
changed the title
Namespace for prefix 'xxx' has not been declared
w3cDom.asString: Namespace for prefix 'xxx' has not been declared
Dec 23, 2023
I'm using a JavaFX WebView to load web pages, which gives us a W3C document which I then convert into a String using the W3CDom class provided by JSoup.
So basically I noticed this crash when trying to use w3CDom.asString() for a site which was created using Vue.js, and it was using "v-bind" in the place of "xxx"
To reproduce you can run the following test case:
The text was updated successfully, but these errors were encountered: