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; }
OutputFormat format = new OutputFormat(document); format.setIndenting(true); format.setOmitXMLDeclaration(true);
private OutputFormat createOutputFormat() { OutputFormat format = new OutputFormat(); format.setIndenting(true); format.setIndent(5); return format; }
/** * Sets the indentation on and off. * <p> * When set on, the default indentation level and default line wrapping is * used (see {@link #getIndentSize()} and {@link #getLineWidth()}). To * specify a different indentation level or line wrapping, use * {@link #setIndent(int)} and {@link #setLineWidth(int)}). * </p> * * @param doIndent * <code>true</code> if indentation should be on */ public void setIndenting(final boolean doIndent) { outputFormat.setIndenting(doIndent); }
/** * Sets the indentation on and off. * <p> * When set on, the default indentation level and default line wrapping is * used (see {@link #getIndentSize()} and {@link #getLineWidth()}). To * specify a different indentation level or line wrapping, use * {@link #setIndent(int)} and {@link #setLineWidth(int)}). * </p> * * @param doIndent * <code>true</code> if indentation should be on */ public void setIndenting(final boolean doIndent) { outputFormat.setIndenting(doIndent); }
OutputFormat format = new OutputFormat(doc); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(System.out, format); serializer.serialize(doc);
/** * @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(); }
public void save() throws AtsConfigurationException { // save the XML file try { OutputFormat format = new OutputFormat(doc); format.setIndenting(true); format.setIndent(4); format.setLineWidth(1000); XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File(atsConfigurationFile)), format); serializer.serialize(doc); } catch (Exception e) { throw new AtsConfigurationException("Error saving ATS configuration in '" + atsConfigurationFile + "'", e); } }
/** * Gets the contents of an XML Document or Element as a nicely formatted string. * This method is useful for debugging. * @param node the Node to print; must be of type Document or Element * @return a nicely formatted String suitable for printing */ public static String serializeNode(Node node) { OutputFormat format = new OutputFormat(); format.setOmitXMLDeclaration(true); format.setIndenting(true); return serializeNode(node,format); }
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); }
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 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(); }
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 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 static String formatXml(String unformattedXml) throws ExecutionPlanConfigurationException { try { 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(); } catch (IOException e) { throw new ExecutionPlanConfigurationException(e); } }
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); }
public static void writeXml(Document document, 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(document); }
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); }