User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » noob xml question Page [1]  
rynop
All American
829 Posts
user info
edit post

I am simply trying to write DOM to an xml file. Here is my code:
// This method writes a DOM document to a file
public static void writeXmlFile(Document doc, String filename) {
try {
// Prepare the DOM document for writing
DOMSource source = new DOMSource(doc);

// Prepare the output file
File file = new File(filename);
file.createNewFile();
StreamResult result = new StreamResult(file);

// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);
} catch (TransformerConfigurationException e) {
} catch (TransformerException e) {
} catch (IOException ioe){
}
}

The incoming filename string is c:\coverted\test.xml. If I create my StreamResult by doing new StreamResult(System.out), it prints out fine. What the hell am i doing wrong? I tried throwin in "file.createNewFile();" because I thougth the transformer might not create the file if it does not exist...but now it just creates the file, and doesnt put any data in it. thx in advance.

1/18/2006 5:59:55 PM

philihp
All American
8349 Posts
user info
edit post

did you .close() it?

1/18/2006 11:04:50 PM

rynop
All American
829 Posts
user info
edit post

I needed to use a Filewriter...

1/19/2006 8:13:24 PM

 Message Boards » Tech Talk » noob xml question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.