[jdom-interest] Getting String from a Document

Brett McLaughlin brett.mclaughlin at lutris.com
Thu Jun 15 08:50:51 PDT 2000


"Thomas M. Sasala" wrote:
> 
>         On the flip side, is there an easy way
> to turn a string into a document?  We're using a
> ByteArrayInputStream now, but that seems a bit
> klunky and kludgy to me.  Also, why assume that
> all input sources of XML data are going to be
> 8-bit input streams?  What if the input source
> is a serialized string?  That's 16-bit unicode.
> The Stream verses Reader goes all the way
> back to the Xerces and DOM tho....

Stream to Document is accomplished using SAXBuilder or DOMBuilder, and
reading that through a Stream (although ByteArrayStream is just one
alternative) seems reasonable to me...

However, I'm not at all opposed to seeing build(<InputType> input,
String encoding) much like we have output(String encoding).  Anyone have
objections to that?

> 
>         FWIW, I have some utils to help with the
> whole process - Element2String, String2Element if
> anyone is interested.

Hmmm... I'm not sure if we want to go down that path (String2Element),
as it opens up a whole can of worms about how a Document or Element is
built. For now, I think we want to ensure that a Document is created
from an XML document, and not delve too deeply into specific
sub-documents to Documents, etc. I'm not saying we won't do those, we
just need to get the core done first.

  However, we have toString() and toSerializedForm() methods on all
constructs, which handle String output.

-Brett

> 
>         -Tom
> 
> Wesley Biggs wrote:
> >
> > ByteArrayOutputStream os = new ByteArrayOutputStream();
> > xmlOutputter.output(document, os);
> > String theOutput = os.toString();
> >
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
Brett McLaughlin
Enhydra Strategist
Lutris Technologies
1200 Pacific Avenue
Santa Cruz, CA  95060



More information about the jdom-interest mailing list