/** * Constructs a new output format with the proper method, * document type identifiers and media type for the specified * document, and with the specified encoding. If <tt>indent</tt> * is true, the document will be pretty printed with the default * indentation level and default line wrapping. * * @param doc The document to output * @param encoding The specified encoding * @param indenting True for pretty printing * @see #setEncoding * @see #setIndenting * @see #whichMethod */ public OutputFormat( Document doc, String encoding, boolean indenting ) { this( doc ); setEncoding( encoding ); setIndenting( indenting ); }
/** * Constructs a new output format with the proper method, * document type identifiers and media type for the specified * document, and with the specified encoding. If <tt>indent</tt> * is true, the document will be pretty printed with the default * indentation level and default line wrapping. * * @param doc The document to output * @param encoding The specified encoding * @param indenting True for pretty printing * @see #setEncoding * @see #setIndenting * @see #whichMethod */ public OutputFormat( Document doc, String encoding, boolean indenting ) { this( doc ); setEncoding( encoding ); setIndenting( indenting ); }
@Override public void printTo(Writer out) throws IOException { if (dom == null) { return; } StringWriter sw = new StringWriter(); OutputFormat format = new OutputFormat(dom); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(sw, format); serializer.serialize(dom); out.write(sw.toString()); out.flush(); }
/** * Constructs a new output format with the default values for * the specified method and encoding. If <tt>indent</tt> * is true, the document will be pretty printed with the default * indentation level and default line wrapping. * * @param method The specified output method * @param encoding The specified encoding * @param indenting True for pretty printing * @see #setEncoding * @see #setIndenting * @see #setMethod */ public OutputFormat( String method, String encoding, boolean indenting ) { setMethod( method ); setEncoding( encoding ); setIndenting( indenting ); }
/** * Constructs a new output format with the default values for * the specified method and encoding. If <tt>indent</tt> * is true, the document will be pretty printed with the default * indentation level and default line wrapping. * * @param method The specified output method * @param encoding The specified encoding * @param indenting True for pretty printing * @see #setEncoding * @see #setIndenting * @see #setMethod */ public OutputFormat( String method, String encoding, boolean indenting ) { setMethod( method ); setEncoding( encoding ); setIndenting( indenting ); }
OutputFormat of = new OutputFormat("XML","windows-1250",true); of.setIndent(1); of.setIndenting(true); XMLSerializer serializer = new XMLSerializer(fos,of); ContentHandler hd = serializer.asContentHandler();
ser._format.setOmitComments((features & COMMENTS)==0); ser._format.setOmitXMLDeclaration((features & XMLDECL) == 0); ser._format.setIndenting((features & FORMAT_PRETTY_PRINT) != 0);
ser._format.setOmitComments((features & COMMENTS)==0); ser._format.setOmitXMLDeclaration((features & XMLDECL) == 0); ser._format.setIndenting((features & FORMAT_PRETTY_PRINT) != 0);
public String format(String unformattedXml) throws IOException, ParserConfigurationException, SAXException { final Document document = parseXmlFile(unformattedXml); OutputFormat format = new OutputFormat(document); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); }
private static OutputFormat getPrettyPrintWithDecl() { OutputFormat fmt = new OutputFormat("XML", "UTF-8", true); fmt.setEncoding("UTF-8"); fmt.setIndenting(true); fmt.setIndent(2); fmt.setOmitXMLDeclaration(false); return fmt; } }
@Override public void save(Writer writer) { logger.fine("Saving configuration"); try { OutputFormat format = new OutputFormat(createDocument()); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); XMLSerializer serializer = new XMLSerializer(writer, format); serializer.serialize(getDocument()); writer.close(); } catch (ConfigurationException ce) { logger.severe("Failed to save configuration: " + ce.getMessage()); } catch (IOException ioe) { logger.severe("Failed to save configuration: " + ioe.getMessage()); } }
final XMLSerializer serializer = new XMLSerializer(out, format); format.setIndenting(true); format.setLineWidth(120); format.setIndent(2);
private static OutputFormat getPrettyPrint() { OutputFormat fmt = new OutputFormat("XML", "UTF-8", true); fmt.setEncoding("UTF-8"); fmt.setIndenting(true); fmt.setIndent(2); fmt.setOmitXMLDeclaration(true); return fmt; }
private static OutputFormat getPrettyPrintWithDecl() { OutputFormat fmt = new OutputFormat("XML", "UTF-8", true); fmt.setEncoding("UTF-8"); fmt.setIndenting(true); fmt.setIndent(2); fmt.setOmitXMLDeclaration(false); return fmt; } }
private static OutputFormat getPrettyPrint() { OutputFormat fmt = new OutputFormat("XML", "UTF-8", true); fmt.setEncoding("UTF-8"); fmt.setIndenting(true); fmt.setIndent(2); fmt.setOmitXMLDeclaration(true); return fmt; }
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"); }
/** * Dumps the SOAPMessage to String * * @param msg the SOAP message * @return the String representation of the message * @throws IOException IO issue * @throws SOAPException SOAP issue */ public String dumpSoapMessage(SOAPMessage msg) throws IOException, SOAPException { Document doc = msg.getSOAPBody().getOwnerDocument(); OutputFormat format = new OutputFormat(doc); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); StringWriter s = new StringWriter(); XMLSerializer serializer = new XMLSerializer(s, format); serializer.serialize(doc); return s.toString(); }