//Serialize DOM OutputFormat format = new OutputFormat (doc); // as a String StringWriter stringOut = new StringWriter (); XMLSerializer serial = new XMLSerializer (stringOut,format); serial.serialize(doc); // Display the XML System.out.println(stringOut.toString());
public OutputStream write() { XMLConf xmlConfig = createXMLConfiguration(); OutputStream out = new ByteArrayOutputStream(); try { XMLSerializer serializer = new XMLSerializer(out, createOutputFormat()); serializer.serialize(xmlConfig.getDocument()); out.close(); } catch (IOException e) { throw new RuntimeException(e); } return out; }
public void write(String filename) { if (!filename.endsWith(".xml")) filename += ".xml"; log.info("write vrp: " + filename); XMLConf xmlConfig = createXMLConfiguration(); try { xmlConfig.setFileName(filename); Writer out = new FileWriter(filename); XMLSerializer serializer = new XMLSerializer(out, createOutputFormat()); serializer.serialize(xmlConfig.getDocument()); out.close(); } catch (IOException e) { throw new RuntimeException(e); } }
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); }
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) { Text text = (Text) node;
//Serialize DOM OutputFormat format = new OutputFormat (doc); // as a String StringWriter stringOut = new StringWriter (); XMLSerializer serial = new XMLSerializer (stringOut, format); serial.serialize(doc); // Display the XML System.out.println(stringOut.toString());
@Override public void filter(String URL, byte[] content, DocumentFragment doc, ParseResult parse) { try { XMLSerializer serializer = new XMLSerializer(os, null); serializer.serialize(doc); os.flush(); } catch (IOException e) { e.printStackTrace(); } }
public static void writePrettyPrint(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT); 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(Document ele, Writer out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, PRETTY_PRINT_WITH_DECL); serializer.serialize(ele); }
OutputFormat format = new OutputFormat(doc); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(System.out, format); serializer.serialize(doc);
String xml = "<row>\n" + " <link href=\"Büro.txt\" target=\"_blank\">\n" + " my link\n" + " </link>\n" + " </row>"; InputStream is = new ByteArrayInputStream(xml.getBytes()); Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(is); XMLSerializer xs = new XMLSerializer(); xs.setOutputCharStream(new PrintWriter(System.err)); xs.serialize(doc);
Document doc = ...; OutputFormat format = new OutputFormat(doc); format.setIndenting(true); format.setIndent(2); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(doc);
@Deprecated public static void prettyPrintWithXMLSerializer(Document document, Writer writer, boolean omitXMLDeclaration, boolean omitDocumentType) throws IOException { OutputFormat format = getOutputFormat(omitXMLDeclaration, omitDocumentType); XMLSerializer serializer = new XMLSerializer(writer, format); serializer.serialize(document); }
@Deprecated public static void prettyPrintWithXMLSerializer(Document document, OutputStream out, boolean omitXMLDeclaration, boolean omitDocumentType) throws IOException { OutputFormat format = getOutputFormat(omitXMLDeclaration, omitDocumentType); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); }
OutputFormat format = new OutputFormat(document); //document is an instance of org.w3c.dom.Document format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); String formattedXML = out.toString();
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);
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(); }