public static void writePrettyPrintWithDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
public static void writePrettyPrintWithDecl(Node ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
public static void writeMgmtWithDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, MGMT_WITH_DECL); serializer.serialize(ele); }
public static void writeMgmtNoDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, MGMT_NO_DECL); serializer.serialize(ele); }
public static void writePrettyPrint(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT); serializer.serialize(ele); }
public static void writePrettyPrint(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT); serializer.serialize(ele); }
public static void writePrettyPrintWithDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
public static void writePrettyPrintWithDecl(Node ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
public static void writeMgmtNoDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, MGMT_NO_DECL); serializer.serialize(ele); }
public static void writeMgmtWithDecl(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, MGMT_WITH_DECL); serializer.serialize(ele); }
/** * method: "XML" * charset: "UTF-8" * indenting: FALSE * indent-width: 0 * line-width: 0 * preserve-space: FALSE * omit-XML-declaration: FALSE * omit-DOCTYPE: FALSE * @param ele * @param out * @throws IOException */ public static void writeXmlToUTF8(Element ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, XML_TO_UTF8); serializer.serialize(ele); }
/** * method: "XML" * charset: "UTF-8" * indenting: FALSE * indent-width: 0 * line-width: 0 * preserve-space: FALSE * omit-XML-declaration: FALSE * omit-DOCTYPE: FALSE * @param ele * @param out * @throws IOException */ public static void writeXmlToUTF8(Element ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, XML_TO_UTF8); serializer.serialize(ele); }
/** * method: "XML" * charset: "UTF-8" * indenting: TRUE * indent-width: 2 * line-width: 80 * preserve-space: FALSE * omit-XML-declaration: FALSE * omit-DOCTYPE: TRUE * @param ele * @param out * @throws IOException */ public static void writeConsoleNoDocType(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, CONSOLE_NO_DOCTYPE); serializer.serialize(ele); }
@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(); }
/** * Serialize the dom Document with no preserved space between elements, * but without indenting, line wrapping, omission of XML declaration, or * omission of doctype * @param doc * @param encoding * @param out * @throws IOException */ public static void writeXmlNoSpace(Document doc, String encoding, Writer out) throws IOException { XMLSerializer ser = new XMLSerializer(out, getXmlNoSpace(encoding)); ser.serialize(doc); out.close(); }
/** * Serialize the dom Document with no preserved space between elements, * but without indenting, line wrapping, omission of XML declaration, or * omission of doctype * @param doc * @param encoding * @param out * @throws IOException */ public static void writeXmlNoSpace(Document doc, String encoding, Writer out) throws IOException { XMLSerializer ser = new XMLSerializer(out, getXmlNoSpace(encoding)); ser.serialize(doc); out.close(); }
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(); }
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"); }
@Override public String generateOutput(DocumentRecord documentRecord) { if (Format.XML.equals(documentRecord.getFormat())) { DOMHandle handle = documentRecord.getContent(new DOMHandle()); Document document = handle.get(); OutputFormat format = new OutputFormat(handle.get()); format.setOmitXMLDeclaration(omitXmlDeclaration); StringWriter writer = new StringWriter(); try { new XMLSerializer(writer, format).serialize(document); return writer.toString(); } catch (IOException e) { throw new RuntimeException("Unable to serialize XML document to string: " + e.getMessage(), e); } } else if (logger.isDebugEnabled()) { logger.debug(String.format("Document '%s' has a format of '%s', so will not attempt to remove the XML declaration from it", documentRecord.getUri(), documentRecord.getFormat().name())); } return documentRecord.getContent(new StringHandle()).get(); }