Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
XML and Related Technologies
Converting Document to String
Steve Watson
Ranch Hand
Posts: 38
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How can I convert a Dom Document to a
String
?
Roseanne Zhang
Ranch Hand
Posts: 1953
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
String parsing help.
Document to String
Setting Xpath String to do XPath query
From Document Object to a byte array
Converting Document Object to String
More...