20080219 Tuesday February 19, 2008

Converting a DOM Document to a String

Here is a simple Java method for converting a DOM object into a String. Hope someone finds it useful:

 private String domToString(Document doc) throws TransformerException {
  TransformerFactory tf = TransformerFactory.newInstance();
  Transformer t = tf.newTransformer();
  StringWriter str = new StringWriter();
  StreamResult result = new StreamResult(str);
  DOMSource source = new DOMSource(doc);
  t.transform(source, result);
  return str.toString();
 }

Posted by rickg ( Feb 19 2008, 08:04:39 PM PST ) Permalink Comments [0]

System.genenv() is back!

Maybe I am the last person in the Java world to realize this, but I just found out that System.getenv() was re-enabled in Java 1.5. YES! Turning that off was one of the dumbest things Sun ever did with Java. Glad it made it back. Posted by rickg ( Feb 19 2008, 08:00:46 PM PST ) Permalink Comments [0]