public static void writePrettyPrintWithDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; ... Node n = ...; OutputFormat outputFormat = new OutputFormat(); outputFormat.setOmitXMLDeclaration(true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLSerializer ser = new XMLSerializer(baos, outputFormat); ser.serialize(n); System.out.println(new String(baos.toByteArray()));
public String getString(Document document, boolean indenting, int indent) throws IOException{ OutputFormat format = new OutputFormat(document); format.setLineWidth(200); format.setIndenting(indenting); format.setIndent(indent); format.setPreserveEmptyAttributes(true); format.setEncoding("UTF-8"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLSerializer serializer = new XMLSerializer(baos, format); serializer.asDOMSerializer(); serializer.serialize(document); return baos.toString("UTF-8"); }
ser.setOutputByteStream(out); ser.setOutputByteStream(outputStream); ser.setOutputCharStream(writer); ser.serialize((Document) node); else if (node.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) ser.serialize((DocumentFragment) node); else if (node.getNodeType() == Node.ELEMENT_NODE) ser.serialize((Element) node); else if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) { ser.serialize(node);
prepareForSerialization(ser, wnode); ser._format.setEncoding("UTF-16"); ser.setOutputCharStream(destination); if (wnode.getNodeType() == Node.DOCUMENT_NODE) { ser.serialize((Document)wnode); ser.serialize((DocumentFragment)wnode); ser.serialize((Element)wnode); wnode.getNodeType() == Node.CDATA_SECTION_NODE || wnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) { ser.serialize(wnode);
ser.setOutputByteStream(out); ser.serialize((Document) node); else if (node.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) ser.serialize((DocumentFragment) node); else if (node.getNodeType() == Node.ELEMENT_NODE) ser.serialize((Element) node); else if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) { ser.serialize(node);
prefix.length() == 0) ? XMLSymbols.EMPTY_STRING : fSymbolTable.addSymbol(prefix); if (fNSBinder.getURI(prefix) == null && prefix != null) { fatalError("The replacement text of the entity node '" + node.getNodeName() + "' contains an element node '" attrPrefix.length() == 0) ? XMLSymbols.EMPTY_STRING : fSymbolTable.addSymbol(attrPrefix); if (fNSBinder.getURI(attrPrefix) == null && attrPrefix != null) { fatalError("The replacement text of the entity node '" + node.getNodeName() + "' contains an element node '" checkUnboundNamespacePrefixedNode(child);
/** * Constructs a new serializer that writes to the specified output * stream using the specified output format. If <tt>format</tt> * is null, will use a default output format. * * @param output The output stream to use * @param format The output format to use, null for the default */ public XMLSerializer( OutputStream output, OutputFormat format ) { super( format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setMethod( Method.XML ); setOutputByteStream( output ); }
/** * Constructs a new serializer that writes to the specified writer * using the specified output format. If <tt>format</tt> is null, * will use a default output format. * * @param writer The writer to use * @param format The output format to use, null for the default */ public XMLSerializer( Writer writer, OutputFormat format ) { super( format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setMethod( Method.XML ); setOutputCharStream( writer ); }
/** * Constructs a new LSSerializer. * The constructor turns on the namespace support in <code>XMLSerializer</code> and * initializes the following fields: fNSBinder, fLocalNSBinder, fSymbolTable, * fEmptySymbol, fXmlSymbol, fXmlnsSymbol, fNamespaceCounter, fFeatures. */ public DOMSerializerImpl() { // set default features features |= NAMESPACES; features |= ENTITIES; features |= COMMENTS; features |= CDATA; features |= SPLITCDATA; features |= WELLFORMED; features |= NSDECL; features |= DOM_ELEMENT_CONTENT_WHITESPACE; features |= DISCARDDEFAULT; features |= XMLDECL; serializer = new XMLSerializer(); initSerializer(serializer); }
ser.setOutputByteStream(out); ser.setOutputByteStream(outputStream); ser.setOutputCharStream(writer); ser.serialize((Document) node); else if (node.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) ser.serialize((DocumentFragment) node); else if (node.getNodeType() == Node.ELEMENT_NODE) ser.serialize((Element) node); else if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) { ser.serialize(node);
prepareForSerialization(ser, wnode); ser._format.setEncoding("UTF-16"); ser.setOutputCharStream(destination); if (wnode.getNodeType() == Node.DOCUMENT_NODE) { ser.serialize((Document)wnode); ser.serialize((DocumentFragment)wnode); ser.serialize((Element)wnode); wnode.getNodeType() == Node.CDATA_SECTION_NODE || wnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) { ser.serialize(wnode);
ser.setOutputByteStream(out); ser.serialize((Document) node); else if (node.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) ser.serialize((DocumentFragment) node); else if (node.getNodeType() == Node.ELEMENT_NODE) ser.serialize((Element) node); else if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) { ser.serialize(node);
prefix.length() == 0) ? XMLSymbols.EMPTY_STRING : fSymbolTable.addSymbol(prefix); if (fNSBinder.getURI(prefix) == null && prefix != null) { fatalError("The replacement text of the entity node '" + node.getNodeName() + "' contains an element node '" attrPrefix.length() == 0) ? XMLSymbols.EMPTY_STRING : fSymbolTable.addSymbol(attrPrefix); if (fNSBinder.getURI(attrPrefix) == null && attrPrefix != null) { fatalError("The replacement text of the entity node '" + node.getNodeName() + "' contains an element node '" checkUnboundNamespacePrefixedNode(child);
/** * Constructs a new serializer that writes to the specified output * stream using the specified output format. If <tt>format</tt> * is null, will use a default output format. * * @param output The output stream to use * @param format The output format to use, null for the default */ public XMLSerializer( OutputStream output, OutputFormat format ) { super( format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setMethod( Method.XML ); setOutputByteStream( output ); }
/** * Constructs a new serializer that writes to the specified writer * using the specified output format. If <tt>format</tt> is null, * will use a default output format. * * @param writer The writer to use * @param format The output format to use, null for the default */ public XMLSerializer( Writer writer, OutputFormat format ) { super( format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setMethod( Method.XML ); setOutputCharStream( writer ); }
public static void writePrettyPrintWithDecl(Node ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
/** * Constructs a new LSSerializer. * The constructor turns on the namespace support in <code>XMLSerializer</code> and * initializes the following fields: fNSBinder, fLocalNSBinder, fSymbolTable, * fEmptySymbol, fXmlSymbol, fXmlnsSymbol, fNamespaceCounter, fFeatures. */ public DOMSerializerImpl() { // set default features features |= NAMESPACES; features |= ENTITIES; features |= COMMENTS; features |= CDATA; features |= SPLITCDATA; features |= WELLFORMED; features |= NSDECL; features |= DOM_ELEMENT_CONTENT_WHITESPACE; features |= DISCARDDEFAULT; features |= XMLDECL; serializer = new XMLSerializer(); initSerializer(serializer); }
public void serialize(OutputStream os, Node node, Format format) throws XMLException { try { XMLSerializer ser = createXMLSerializer(node,format); ser.setOutputByteStream(os); serialize(ser,node); } catch(Exception e) { throw new XMLException(e,"Error while converting XML document to string"); // $NLS-AbstractXercesDriver.ErrorwhileconvertingXMLdocumentto-1$ } }