Example 16-10: Extension function to write XML as text markup

import org.w3c.dom.*;
import oracle.xml.parser.v2.*;
import java.io.*;
public class MarkupExtensions {
  public static String xmlMarkup(NodeList nl) throws Exception {
    if (nl != null) {
      // Wrap a StringWriter by a PrintWriter
      StringWriter sw = new StringWriter();
      PrintWriter  pw = new PrintWriter(sw);
      int nodes = nl.getLength();
      // Loop over the nodes in the node list. Tell each one to print itself
      for (int z = 0; z < nodes ; z++ ) {
        // Print XML Markup for Current Node
        ((XMLNode)nl.item(z)).print(pw);
      }
      // Return the StringBuffer of the StringWriter
      return sw.toString();
    }
    return "";
  }
}