I have XML as shown below:
<documentation>
This value must be <i>bigger</i> than the other.
</documentation>
Using JDOM, I can get the following text structures:
Document d = new SAXBuilder().build( new StringReader( s ) );
System.out.printf( "getText: '%s'%n", d.getRootElement().getText() );
System.out.printf( "getTextNormalize: '%s'%n", d.getRootElement().getTextNormalize() );
System.out.printf( "getTextTrim: '%s'%n", d.getRootElement().getTextTrim() );
System.out.printf( "getValue: '%s'%n", d.getRootElement().getValue() );
which give me the following outputs:
getText: '
This value must be than the other.
'
getTextNormalize: 'This value must be than the other.'
getTextTrim: 'This value must be than the other.'
getValue: '
This value must be bigger than the other.
'
I really wanted to get the contents of the element as a string, namely "This value must be <i>bigger</i> than the other.". getValue()approaches, but removes the tag <i>. I guess I wanted something like innerHTMLfor XML documents ...
Should I just use XMLOutputter for the content? Or is there a better alternative?
source
share