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 (XML4J-src_3_0_1.zip). 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 ---
import java.io.PrintWriter;
--- 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;