[jdom-interest] Content missing after conversion from W3C Element to JDOM2 Element
jdom at tuis.net
Wed Nov 7 16:07:29 PST 2012
I am back home, and I have my JDOM code in front of me.
I have just gone through the code, and 'it works for me'. What this
- you load a Document using a DOM DocumentBuilderFactory supplied by Xerces
- and you pass that document to JDOM to build a JDOM document
- and that document contains Text nodes
- JDOM will correctly translate those DOM Text nodes in to JDOM Text nodes.
Now, I am not saying that using the getTextContent() is the 'right'
method to call. It is possible that I would be better off using
getNodeValue(). In fact, in JDOM versions before 2.x it used
getNodeValue(). I can't think of why I decided to use getTextContent()
instead other than the fact that that part of code was refactored
significantly, and I used the documentation carefully, and perhaps there
was something that used getTextContent() and I chose to do it that way.
I have just run the entire test suite with the code changed to use
getNodeValue() and it still works fine for me.
On checking the DOM specification, the getTextContent() method was added
in DOM level 3.
The Java API documentation is a mess in this area.... JDK 1.5 package
information indicates that the org.w3c.dom API supports DOM Level 2:
Yet, the Node class indicates it implements Level 3..... and it exposes
all the Level 3 changes.
In fact, the Java5 new features indicate that:
JAXP implements the Level3 specification.
So, what this means is that:
- JDOM is doing the right thing
- It uses functionality supported since Java5
- it is probably your particular DOM library that has a broken
implementation of the new-to-DOM3 method getTextContent()
- JDOM does not need to use getTextContent() because the old method
getNodeValue() will work just fine.
What would be useful is if you could determine the library that you are
using. Since you have already 'hacked' the code, why don't you
temporarily add the line: System.out.println(text.getClass()); to the
method. This will tell you the concrete implementation of DOM that's broken.
I will also change the text() method to use getNodeValue() instead... it
makes sense to do it if there's a broken library, and it's no big deal
for JDOM.... Also, I am planning a release imminently, so the timing is
If you could get back to me on what library you are using, I will dig in
to it and we can see if there's a fix for your library (I imagine that
I did google for "getTextContent bug Text Node" but I find no seemingly
Created issue #100 for this: https://github.com/hunterhacker/jdom/issues/100
On 07/11/2012 5:48 PM, Larsen wrote:
> I will try to test this tomorrow in my company.
> On Wed, 07 Nov 2012 22:48:48 +0100, Rolf Lear <jdom at tuis.net> wrote:
>> If you pull the JDOM code from github, set it up as an eclipse project
>> (if you use eclipse...), then right-click the build.xml file and run
>> the eclipse target. If you use eclipse you can then right-click the
>> project and run all tests, or you can run the ant junit target.
>> As for which DOM you use, run your project with the java option
>> -Djaxp.debug=1 to see which DOM is found.
>> Larsen <larsen007 at web.de> wrote:Hi Rolf,
>> I haven´t used unit tests so far and would need some instructions on
>> howto run them in case this becomes necessary.
>> How can I check for a buggy DOM implementation?
>> On Wed, 07 Nov 2012 19:31:09 +0100, Rolf Lear <jdom at tuis.net> wrote:
>>> Hi (again).
>>> Based on some double-checking, I suspect that you have a buggy
>>> GetTextContent returns nodeBalue for Text nodes...
>>> Node.getTextContentsays it should anyway.
>>> I will check it out some more later.
>>> Larsen <larsen007 at web.de> wrote:> I am quite a JDOM2 newbie and
>>> noticedstrange/incorrect behaviour when
>>>> converting a W3C-Element to a JDOM-Element. (snip)
>>> PS: Using latest JDOM 2.0.3 and Java 7 ("1.7.0_09")
>>> To control your jdom-interest membership:
>> To control your jdom-interest membership:
> To control your jdom-interest membership:
More information about the jdom-interest