Java Code Examples for org.apache.xml.serialize.XMLSerializer#asContentHandler()

The following examples show how to use org.apache.xml.serialize.XMLSerializer#asContentHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlEditsVisitor.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Create a processor that writes to the file named and may or may not
 * also output to the screen, as specified.
 *
 * @param filename Name of file to write output to
 * @param printToScreen Mirror output to screen?
 */
public XmlEditsVisitor(OutputStream out)
    throws IOException {
  this.out = out;
  OutputFormat outFormat = new OutputFormat("XML", "UTF-8", true);
  outFormat.setIndenting(true);
  outFormat.setIndent(2);
  outFormat.setDoctype(null, null);
  XMLSerializer serializer = new XMLSerializer(out, outFormat);
  contentHandler = serializer.asContentHandler();
  try {
    contentHandler.startDocument();
    contentHandler.startElement("", "", "EDITS", new AttributesImpl());
  } catch (SAXException e) {
    throw new IOException("SAX error: " + e.getMessage());
  }
}
 
Example 2
Source File: XmlEditsVisitor.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Create a processor that writes to the file named and may or may not
 * also output to the screen, as specified.
 *
 * @param filename Name of file to write output to
 * @param printToScreen Mirror output to screen?
 */
public XmlEditsVisitor(OutputStream out)
    throws IOException {
  this.out = out;
  OutputFormat outFormat = new OutputFormat("XML", "UTF-8", true);
  outFormat.setIndenting(true);
  outFormat.setIndent(2);
  outFormat.setDoctype(null, null);
  XMLSerializer serializer = new XMLSerializer(out, outFormat);
  contentHandler = serializer.asContentHandler();
  try {
    contentHandler.startDocument();
    contentHandler.startElement("", "", "EDITS", new AttributesImpl());
  } catch (SAXException e) {
    throw new IOException("SAX error: " + e.getMessage());
  }
}