我有一个如下的 XML:
<documentation>
This value must be <i>bigger</i> than the other.
</documentation>
使用 JDOM,我可以获得以下文本结构:
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() );
这给了我以下输出:
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.
'
我真正想要的是将元素的内容作为字符串获取,即"This value must be <i>bigger</i> than the other."
. getValue()
接近但删除<i>
标签。我想我想要类似innerHTML
XML 文档的东西......
我应该只在内容上使用 XMLOutputter 吗?还是有更好的选择?