How to print  a Document in JAXP 1.1

Posted on 2001-08-09
Last Modified: 2012-08-13
As we know, it is easy to parse a .xml file and construct a Document object using DocumentBuilder object. However, I need to do the reverse construction. That's to say, I have a Document object, and need print the Document to a file.   Does anybody know how to do it?

Thanks, bob.
Question by:bobli
  • 2

Accepted Solution

mattyk earned 200 total points
Comment Utility
Take a look at the page Writing Out a DOM as an XML File

In version 1.0 you could use the XMLDocument interface that Sun provided.  
In JAXP 1.1 there is a new method to do this:

 import javax.xml.transform.*;
 import javax.xml.transform.dom.*;

 //normal xml code to create DOM called document goes here

 //now write out to FileStream
 TransformerFactory transformerFactory =

  Transformer serializer = transformerFactory.newTransformer();

 serializer.transform( new DOMSource( document ),
            new StreamResult( new FileOutputStream( "intro1.xml" ) ) );



Expert Comment

Comment Utility

  Any luck with this?  


Author Comment

Comment Utility
Yes, It works fine. Thanks matty.


Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now