?
Solved

How to print  a Document in JAXP 1.1

Posted on 2001-08-09
3
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
mattyk earned 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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