Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Writing a DOM's contents to a String  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know if there is a quick and easy way (using JAXP or any other Java XML parser) to convert the contents of a DOM to a String?
I am used to working with Microsoft's parser so I apologize for the comparison (again), but MSXML's DOMDocument object has a method, .xml() which will convert the contents of the DOM into a String.
l_sXML = l_oXML.xml
Debug.Print l_sXML
The output might be something like "<junk><stuff>This is junk</stuff></junk>". This can then be passed around in code as a String.
Anything like this in a (Java) DOM?
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the XMLSerializer that comes bundled with Xerces.
Here's a small code example -

Note that since XMLSerializer can write to any OutputStream, you can either write to a file or a String.
Hope that helps!

Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
[This message has been edited by Ajith Kallambella (edited June 07, 2001).]
Men call me Jim. Women look past me to this tiny ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!