Refine search
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; }
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 format.setLineSeparator(LINE_SEP); } else { format.setLineSeparator(""); XMLSerializer serial = new XMLSerializer(writer, format); serial.asDOMSerializer(); if (node instanceof Document) { serial.serialize((Document) node); } else if (node instanceof Element) { format.setOmitXMLDeclaration(true); serial.serialize((Element) node); } else if (node instanceof DocumentFragment) { format.setOmitXMLDeclaration(true); serial.serialize((DocumentFragment) node); } else if (node instanceof Text) {
OutputFormat format = new OutputFormat(document); format.setIndenting(true); format.setOmitXMLDeclaration(true);
/** * @deprecated relies on XMLSerializer which is a deprecated Xerces class, use domToString instead */ static public String prettyPrint(Element e) throws IOException { OutputFormat format = new OutputFormat(e.getOwnerDocument()); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); StringWriter out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(e); return out.toString(); }
default void printDocument(Document doc) throws Exception { OutputFormat format = new OutputFormat(doc); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(System.out, format); serializer.serialize(doc); }
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; }
public static void writeXml(Element element, Writer out, int indent) throws IOException { OutputFormat format = new OutputFormat("XML", "UTF-8", false); format.setOmitComments(false); if (indent > 0) { format.setIndenting(true); format.setIndent(indent); } format.setLineWidth(0); XMLSerializer serializer = new XMLSerializer(format); serializer.setOutputCharStream(out); serializer.serialize(element); }
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; }
/** * Serializes document. * * @param doc an org.w3c.dom.Document object. * @param writer a java.io.Writer object. * @throws Exception if unable to serialize the document. */ public static void serializeDoc(Document doc, Writer writer) throws java.lang.Exception { XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml", "UTF-8", true)); s.serialize(doc); }
/** * 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)); }
public static void writeXml(Element element, OutputStream os) throws IOException { OutputFormat format = new OutputFormat("XML", "UTF-8", false); format.setOmitComments(false); format.setLineWidth(0); XMLSerializer serializer = new XMLSerializer(format); serializer.setOutputByteStream(os); serializer.serialize(element); }
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); }
/** * 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()); } }
/** Generate the html string from the given element */ public static String getHtmlStream(Element element) { StringWriter w = new StringWriter(); // XXX initial size? OutputFormat format = new OutputFormat(element.getOwnerDocument(), null, true); // default enc, do-indent format.setLineWidth(160); format.setIndent(4); JspxSerializer serializer = new JspxSerializer(w, format); try { serializer.serialize(element); } catch (java.io.IOException ex) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } return w.getBuffer().toString(); }
public static String serialize(XmlSerializable serializable) throws IOException { StringWriter out = new StringWriter(); try { Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", true); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); return out.toString(); } catch (ParserConfigurationException e) { throw new CosmoParseException(e); } } }
OutputFormat format = new OutputFormat(); 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)) ); format.setPreserveEmptyAttributes(true); format.setLineWidth(80); format.setIndenting(true); format.setIndent(2); format.setPreserveSpace( preserveSpace );
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); }
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); }
public static String toStringOmitXml(Element element) throws IOException { OutputFormat of = new OutputFormat(); of.setOmitXMLDeclaration(true); return toString(element, of); }