Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Converting DOM XML to String [Thread Next] Re: Converting DOM XML to StringTo: NULL Date: 2/5/2007 4:36:00 PM
esor50 <mrosm@a...> wrote:
> I create and populate the XML in a document. Then I find that, in
> order to put my XML into a String, I need to serialize the document to
> a file. I then read the string from the file. This approach is
> working but it seems crazy to me; is there a way to convert the XML in
> the document to a String without putting it into a file?
Something like:
byte[] bytes = myXMLString.getBytes( "UTF-8" );
ByteArrayInputStream bis = new ByteArrayInputStream( bytes );
StreamSource source = new StreamSource( bis );
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
DOMResult result = new DOMResult( doc );
Transformer xform = TransformerFactory.newInstance().newTransformer();
xform.transform( source, result );
return doc;
This was a copy/paste from working code, so it's not guaranteed to be 100%
correct, but it'll point you in the right direction.
- Paul
P.S.: It seems like an aweful lot of work, doesn't it?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
