Solved

How to print  a Document in JAXP 1.1

Posted on 2001-08-09
3
181 Views
Last Modified: 2012-08-13
HI,
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.
0
Comment
Question by:bobli
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
mattyk earned 200 total points
ID: 6370738
Take a look at the page Writing Out a DOM as an XML File
 at:

http://java.sun.com/xml/jaxp-1.1/docs/tutorial/xslt/2_write.html


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.*;
 import javax.xml.transform.stream.*;

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

 //now write out to FileStream
 TransformerFactory transformerFactory =
            TransformerFactory.newInstance();

  Transformer serializer = transformerFactory.newTransformer();

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




-matty

 
0
 
LVL 5

Expert Comment

by:mattyk
ID: 6375555
Bobli,

  Any luck with this?  

-matty
0
 

Author Comment

by:bobli
ID: 6380062
Yes, It works fine. Thanks matty.

bob
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

21 Experts available now in Live!

Get 1:1 Help Now