[jdom-interest] Getting mixed content as string?

Jason Hunter jhunter at collab.net
Tue Jul 4 12:17:27 PDT 2000


> Remind me again, what method should I call to get the string
> 
> "<a href='http://www.jguru.com/'>jGuru</a>, the rockingest Java
> portal, is ready for action."
> 
> from the source element
> 
> <item>
> <title>jGuru Launches</title>
> <url>http://www.jguru.com</url>
> <date>December, 1999</date>
> <description>
> <a href='http://www.jguru.com/'>jGuru</a>,
> the rockingest Java portal, is ready for action.
> </description>
> </item>
> 
> ?
> 
> I tried item.getChild("description").getSerializedForm() and it didn't
> work (some unimplemented exception i think); tried getContent() and it
> skipped the <a> element.  getMixedContent(), of course, returns a
> List, not a String, and I'd have to write a recursive loop to convert
> it.
> 
> If it doesn't work, then I'd like to propose something like
> getTextContent() or getStringContent() or getMixedStringContent() that
> would work as desired.

No need to propose a new method; that's what getSerializedForm() is
supposed to do.  It's just, as you saw, unimplemented.  The reason is
that to do this right we need to hook into XMLOutputter and let it
handle the output.  There's no reason to reproduce output logic in two
places, after all.  But do we really want a public API on XMLOutputter
for outputting every piece of an XML document?  Right now the methods
are protected so subclasses can make use of them.  If the classes were
in the same package, we could use default access, but they're not and
shouldn't be.  Feel free to propose a good design, I'm supposed to be
doing book writing today and don't have time to think about it.  :-)

-jh-



More information about the jdom-interest mailing list