Skip to content
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

Element.getContentSize() gives different result with CDATA between v1.1 and v2.0.6 #173

oberstnova opened this issue Sep 3, 2018 · 1 comment


Copy link


just finally migrated from jdom 1.1 to jdom 2.0.6.
However I have an example where org.jdom2.Element.getContentSize() returns another result than the Version 1.1 counterpart did, which breaks some dependent code.


Document doc = null;
try {
    File f = new File("C:\\...\\RPTXXMLTEST.xml");
    // In Version 1.1 this was new SAXBuilder(false)
    doc = new SAXBuilder( XMLReaders.NONVALIDATING ).build( f );
    Element rootElement = doc.getRootElement();
    System.out.println("Content Size is " + rootElement.getContentSize());
} catch( Exception e ) {

Corresponding RPTXXMLTEST.xml is getting attached.
(Content as it's not much:)

<?xml version="1.0" encoding="UTF-8"?>

In Version 1.1 the Result was "Content Size is 1" - in 2.0.6 it's "Content Size is 2".
As it is a single element I would await a contentSize of "1".

Is the new behaviour expected and if yes, then why?

Thanks for your efforts.

Copy link

rolfl commented Jul 2, 2021

Hadling of Text interleaved with CDATA is an interesting case when characters are received from SAX parser. The code previously started in "expecting Text" content mode, and would create an empty Text member if the first content is CDATA.

rolfl added a commit that referenced this issue Jul 2, 2021
Also includes test case for #173 that was missed in previous commit
@rolfl rolfl closed this as completed in 0defeed Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants