Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to print  a Document in JAXP 1.1

Posted on 2001-08-09
3
Medium Priority
?
209 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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