private static XMLSerializer getXMLSerializer(final OutputStream os, final String[] cdataElements) throws InstantiationException, IllegalAccessException, ClassNotFoundException { // configure an OutputFormat to handle CDATA final OutputFormat of = new OutputFormat(); // specify which of your elements you want to be handled as CDATA. // The use of the '^' between the namespaceURI and the localname // seems to be an implementation detail of the xerces code. // When processing xml that doesn't use namespaces, simply omit the // namespace prefix as shown in the third CDataElement below. of.setCDataElements(cdataElements); // set any other options you'd like of.setPreserveSpace(true); of.setIndenting(true); // create the serializer final XMLSerializer serializer = new XMLSerializer(of); serializer.setOutputByteStream(os); return serializer; }
private OutputFormat createOutputFormat() { OutputFormat format = new OutputFormat(); format.setIndenting(true); format.setIndent(5); return format; }
public static void validate( Document doc, String schemaLocationPropertyValue, EntityResolver resolver) throws IOException, SAXException { OutputFormat format = new OutputFormat(doc, null, true); StringWriter writer = new StringWriter(1000); XMLSerializer serial = new XMLSerializer(writer, format); serial.asDOMSerializer(); serial.serialize(doc); String docString = writer.toString(); validate(docString, schemaLocationPropertyValue, resolver); }
OutputFormat format; if (doc != null) { format = new OutputFormat(doc, null, prettyPrint); } else { format = new OutputFormat("xml", null, prettyPrint); format.setLineWidth(0); // don't wrap lines
/** * Constructs a new serializer. The serializer cannot be used without * calling {@link #setOutputCharStream} or {@link #setOutputByteStream} * first. */ public HTMLSerializer( OutputFormat format ) { this( false, format != null ? format : new OutputFormat( Method.HTML, "ISO-8859-1", false ) ); }
/** * Constructs a new serializer. The serializer cannot be used without * calling {@link #setOutputCharStream} or {@link #setOutputByteStream} * first. */ public HTMLSerializer() { this( false, new OutputFormat( Method.HTML, "ISO-8859-1", false ) ); }
/** * 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 XML11Serializer( OutputStream output, OutputFormat format ) { super( output, format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setVersion("1.1"); }
/** * Constructs a new serializer. The serializer cannot be used without * calling {@link #setOutputCharStream} or {@link #setOutputByteStream} * first. */ public XMLSerializer( OutputFormat format ) { super( format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setMethod( Method.XML ); }
/** * This is the XMLSerializer responsible for outputting the XML document */ protected XMLSerializer getSerializer(final Writer out) { return new XMLSerializer(out, new OutputFormat(Method.XML, getEncoding(), true)); }
private void writeDocument(Document document, OutputStream out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, new OutputFormat(document, null, true)); serializer.serialize(document); }
/** * Encodes the internal object representation of a parameter as a string. */ public void encode( Object value, OutputStream os) throws Exception { // create the document serializer XMLSerializer serializer = new XMLSerializer(os, new OutputFormat()); serializer.setNamespaces(true); // cascade on the other encode method encode(value, serializer); }
public static String toStringOmitXml(Element element) throws IOException { OutputFormat of = new OutputFormat(); of.setOmitXMLDeclaration(true); return toString(element, of); }
@XContent("description") public void setDescription(DocumentFragment descriptionDOM) { try { OutputFormat of = new OutputFormat(); of.setOmitXMLDeclaration(true); this.description = DOMSerializer.toString(descriptionDOM, of).trim(); } catch (IOException e) { log.error(e, e); } }
private static XMLSerializer getXMLSerializer( OutputStream os ) throws InstantiationException, IllegalAccessException, ClassNotFoundException { OutputFormat of = new OutputFormat(); of.setCDataElements( new String[] { "ns1^commentText", "ns2^commentText", "^commentText" } ); XMLSerializer serializer = new XMLSerializer( of ); serializer.setOutputByteStream( os ); return serializer; }
private static OutputFormat getXmlNoSpace(String encoding) { OutputFormat fmt = new OutputFormat("XML", encoding, false); // indent == 0 means add no indenting fmt.setIndent(0); // default line width is 72, but only applies when indenting fmt.setLineWidth(0); fmt.setPreserveSpace(false); return fmt; }
public static String format(String unformattedXml) throws IOException, ParserConfigurationException, SAXException { final Document document = parseXmlFile(unformattedXml); OutputFormat format = new OutputFormat(document); format.setLineWidth(LINE_WIDTH); format.setIndenting(true); format.setIndent(INDENT); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); }
public static ContentHandler getXercesSerializer(OutputStream os) { XMLSerializer serializer = new XMLSerializer(); OutputFormat format = new OutputFormat(); format.setPreserveSpace(true); format.setOmitDocumentType(true); serializer.setOutputFormat(format); serializer.setOutputByteStream(os); return serializer; } }
private static OutputFormat getConsoleWithDocType() { OutputFormat fmt = new OutputFormat("XML", "UTF-8", true); fmt.setIndent(2); fmt.setLineWidth(80); fmt.setPreserveSpace(false); // default is false fmt.setOmitXMLDeclaration(false); // default is false fmt.setOmitDocumentType(false); return fmt; }
/** Get the output format to be used when serializing this buffer */ public OutputFormat getOutputFormat() { String xencoding = getIanaEncoding(getEncoding()); OutputFormat format = new OutputFormat(sourceDocument, xencoding, true); // do-indent==true format.setLineWidth(160); format.setIndent(4); format.setAllowJavaNames(true); return format; }
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); }