How do I save a DOM as a local file using XML4j by IBM?

Robert Sullivan

You might want to modify one of the XML4j samples to write to a file. This assumes you're using plain server-side code, no bean or servlet issues addressed here.

The XML4J sample dom/DomWriter will write XML to standard output. It comes with the source package ( Here's what I did:

1. I added the necessary import.
2. I added a constructor that took a filename parameter.
3. I called the new constructor.
4. I also set 'canonical' to false.

---cut import ---
--- cut ----

-- cut constructor---
public DOMWriter(String filename, String encoding, boolean canonical)
throws Exception {
out = new PrintWriter(new
OutputStreamWriter(new FileOutputStream(filename), encoding), true);
this.canonical = canonical;
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact