A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Engineering
»
XML and Related Technologies
Author
Converting Document to String
Steve Watson
Ranch Hand
Joined: Apr 08, 2003
Posts: 38
posted
Apr 17, 2003 12:40:00
0
How can I convert a Dom Document to a
String
?
Roseanne Zhang
Ranch Hand
Joined: Nov 14, 2000
Posts: 1953
posted
Apr 21, 2003 19:21:00
0
Here is the code:
public static String returnDocAsString(Document doc) { StringWriter sw = new StringWriter(); try { TransformerFactory tfFac = TransformerFactory.newInstance(); // use null trandformation Transformer tf = tfFac.newTransformer(); tf.transform(new DOMSource(doc), new StreamResult(sw)); } catch (TransformerException e) { e.printStackTrace(); } return sw.toString(); }
The full working example can be found at
http://bobcat.webappcabaret.net/javachina/faq/xml_java_01.htm#jaxp_dom_Q35
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Converting Document to String
Similar Threads
Document to String
Setting Xpath String to do XPath query
From Document Object to a byte array
String parsing help.
Converting Document Object to String
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter