/** * Sets the charset encoding scheme to be used in encoding XML content. * <p> * This encoding will determine the resulting character encoding for the XML * content generated by this Encoder and will be reflected in the XML * declaration tag. * </p> * * @param charset * the (non null) charset to encode XML content accordingly to */ public void setEncoding(final Charset charset) { final String charsetName = charset.name(); outputFormat.setEncoding(charsetName); }
/** * Sets the charset encoding scheme to be used in encoding XML content. * <p> * This encoding will determine the resulting character encoding for the XML * content generated by this Encoder and will be reflected in the XML * declaration tag. * </p> * * @param charset * the (non null) charset to encode XML content accordingly to */ public void setEncoding(final Charset charset) { final String charsetName = charset.name(); outputFormat.setEncoding(charsetName); }
/** * 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 ); }
private String prettyPrint(byte[] bytes) throws Exception { Source source = new StreamSource(new ByteArrayInputStream(bytes)); DOMResult result = new DOMResult(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer identityTransformer = transformerFactory.newTransformer(); identityTransformer.transform(source, result); Document doc = (Document) result.getNode(); OutputFormat format = new OutputFormat(doc); format.setEncoding("UTF-8"); format.setIndenting(true); format.setIndent(2); format.setLineWidth(80); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLSerializer xmlSerializer = new XMLSerializer(out, format); xmlSerializer.serialize(doc); return out.toString("UTF-8"); } }
/** * 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 ); }
private void copySettings(XMLSerializer src, XMLSerializer dest) { dest.fDOMErrorHandler = fErrorHandler; dest._format.setEncoding(src._format.getEncoding()); dest._format.setLineSeparator(src._format.getLineSeparator()); dest.fDOMFilter = src.fDOMFilter; }//copysettings
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 XMLSerializer createXMLSerializer(Node node, Format fmt) { if(fmt==null) { fmt = Format.defaultFormat; } OutputFormat format = new OutputFormat(); //node.getOwnerDocument()); format.setIndent(fmt.indent); format.setOmitXMLDeclaration(!fmt.xmlDecl); format.setEncoding(fmt.encoding); return new XMLSerializer(format); }
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 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; } }
/** * Converts a <code>Document</code> into a formated XML string. * @param doc <code>Document</code> to be converted into a string. * @return a string representing the formated XML document */ public static String toString( Document doc ) { StringWriter str = new StringWriter(); try { OutputFormat out = new OutputFormat(doc); out.setIndenting(true); out.setIndent(1); out.setStandalone(false); out.setEncoding("UTF-8"); out.setLineWidth(0); XMLSerializer ser = new XMLSerializer(str, out); ser.serialize(doc.getDocumentElement()); } catch( Exception e ) { return null; } return str.toString(); }
/** * Writes the Kalumet agent XML log file using in-memory DOM. */ public synchronized void writeXMLFile() { try { OutputFormat format = new OutputFormat(); format.setLineWidth( 72 ); format.setIndenting( true ); format.setIndent( 3 ); format.setEncoding( "ISO-8859-1" ); XMLSerializer serializer = new XMLSerializer( new FileOutputStream( this.basedir + "/" + MAIN_LOG_FILE ), format ); serializer.serialize( this.toDOMElement( new CoreDocumentImpl( true ) ) ); } catch ( Exception e ) { LOG.error( "Can't write update log file.", e ); } }
/** * Converts a <code>Document</code> into a formated XML string. * @param doc <code>Document</code> to be converted into a string. * @return a string representing the formated XML document */ public static String toString( Document doc ) { StringWriter str = new StringWriter(); try { OutputFormat out = new OutputFormat(doc); out.setIndenting(true); out.setIndent(1); out.setStandalone(false); out.setEncoding("UTF-8"); out.setLineWidth(0); XMLSerializer ser = new XMLSerializer(str, out); // normalizeDocument adds "xmlns" attributes, among other normalization doc.normalizeDocument(); // XXX: should we clone the document? ser.serialize(doc.getDocumentElement()); } catch( Exception e ) { return null; } return str.toString(); }
format.setIndenting( true ); format.setIndent( 3 ); format.setEncoding( "ISO-8859-1" ); if ( path.startsWith( "http:" ) || path.startsWith( "http:" ) )
format.setIndenting( true ); format.setIndent( 3 ); format.setEncoding( "ISO-8859-1" ); if ( path.startsWith( "http:" ) || path.startsWith( "http:" ) )
format.setEncoding(outputEncoding); format.setEncoding(outputEncoding); format.setOmitXMLDeclaration( "true".equals(policy.getDirective(Policy.OMIT_XML_DECLARATION)) ); format.setOmitDocumentType( "true".equals(policy.getDirective(Policy.OMIT_DOCTYPE_DECLARATION)) );
public SerializingUserLayoutDao() { layoutOutputFormat=new OutputFormat(); layoutOutputFormat.setIndenting(true); layoutOutputFormat.setLineWidth(0); layoutOutputFormat.setOmitDocumentType(false); layoutOutputFormat.setPreserveSpace(true); layoutOutputFormat.setEncoding("UTF-8"); layoutOutputFormat.setOmitComments(false); layoutOutputFormat.setOmitXMLDeclaration(false); layoutOutputFormat.setDoctype(publicDoctype, systemDoctype); }
try { prepareForSerialization(ser, wnode); ser._format.setEncoding("UTF-16"); ser.setOutputCharStream(destination); if (wnode.getNodeType() == Node.DOCUMENT_NODE) {
ser._format.setEncoding(encoding); ser.setOutputByteStream(XMLEntityManager.createOutputStream(URI));