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 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 writePrettyPrint(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT); serializer.serialize(ele); }
import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; ... Node n = ...; OutputFormat outputFormat = new OutputFormat(); outputFormat.setOmitXMLDeclaration(true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLSerializer ser = new XMLSerializer(baos, outputFormat); ser.serialize(n); System.out.println(new String(baos.toByteArray()));
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 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); }
import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; import java.io.File; import java.io.FileOutputStream; ... //your document Document doc = dBuilder.parse(fXmlFile); OutputFormat format = new OutputFormat(doc); format.setIndenting(true); FileOutputStream fos = new FileOutputStream(new File("your-file")); try { XMLSerializer serializer = new XMLSerializer(fos, format); serializer.serialize(doc); } finally { fos.close(); }
@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(); }
private Serializer getSerializer( OutputFormat format ) { if ( _method.equals( Method.XML ) ) { return new XMLSerializer( format ); } else if ( _method.equals( Method.HTML ) ) { return new HTMLSerializer( format ); } else if ( _method.equals( Method.XHTML ) ) { return new XHTMLSerializer( format ); } else if ( _method.equals( Method.TEXT ) ) { return new TextSerializer(); } else { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method}); throw new IllegalStateException(msg); } }
private Serializer getSerializer( OutputFormat format ) { if ( _method.equals( Method.XML ) ) { return new XMLSerializer( format ); } else if ( _method.equals( Method.HTML ) ) { return new HTMLSerializer( format ); } else if ( _method.equals( Method.XHTML ) ) { return new XHTMLSerializer( format ); } else if ( _method.equals( Method.TEXT ) ) { return new TextSerializer(); } else { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method}); throw new IllegalStateException(msg); } }
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(); }
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 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"); }