protected void writeXML(final Document doc, final File f) throws IOException, XMLException { try { OutputStream out = new FileOutputStream(f); out = new BufferedOutputStream(out); // getDocumentCharset(f) - to retrieve the charset encoding attribute Serializer serializer = new Serializer(out, XMLUtil.getDocumentCharset(f)); serializer.write(doc); out.close(); } catch (IOException ex) { throw new XMLException(ex.getMessage(), ex); } }
@Deprecated public static String indentXML(final String in) throws XMLException, IOException { try { Builder parser = new Builder(); Document doc = parser.build(in, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Serializer serializer = new Serializer(baos); serializer.setIndent(4); serializer.setMaxLength(69); serializer.write(doc); return new String(baos.toByteArray()); } catch (ParsingException ex) { // LOG.log(Level.SEVERE, null, ex); throw new XMLException("XML indentation failed.", ex); } } }
/** {@inheritDoc} */ @Override public void print(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); if (options.pretty) { ser.setIndent(2); } else { ser.setIndent(0); } ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
/** overrides element writing. allows updating of XOM before * * @param element * @throws IOException */ protected void write(Element element) throws IOException { if (element instanceof CMLElement) { // ((CMLElement) element).updateXOM(); } super.write(element); }
private void writeChanges(Document pom) { Serializer serializer = createSerialiser(); try { serializer.write(pom); } catch (IOException e) { throw new RuntimeException(e); } }
private void writeChanges(Document pom) { Serializer serializer = createSerialiser(); try { serializer.write(pom); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void write(OutputStream out) throws IOException { makeSerializer(out).write(content); } protected Serializer makeSerializer(OutputStream out) throws UnsupportedEncodingException {
public static String prettyXml(Document doc) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Serializer serializer = new Serializer(out); serializer.setIndent(2); serializer.write(doc); return out.toString("UTF-8"); }
public static String xmlFromDocument(Document doc) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Serializer serializer = new Serializer(baos, "UTF-8"); serializer.setIndent(4); serializer.write(doc); return baos.toString("UTF-8"); }
private Source convertResponse(Element responseElement) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Serializer serializer = createSerializer(os); Document document = responseElement.getDocument(); if (document == null) { document = new Document(responseElement); } serializer.write(document); byte[] bytes = os.toByteArray(); return new StreamSource(new ByteArrayInputStream(bytes)); }
private Source convertResponse(Element responseElement) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Serializer serializer = createSerializer(os); Document document = responseElement.getDocument(); if (document == null) { document = new Document(responseElement); } serializer.write(document); byte[] bytes = os.toByteArray(); return new StreamSource(new ByteArrayInputStream(bytes)); }
private Source convertResponse(Element responseElement) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Serializer serializer = createSerializer(os); Document document = responseElement.getDocument(); if (document == null) { document = new Document(responseElement); } serializer.write(document); byte[] bytes = os.toByteArray(); return new StreamSource(new ByteArrayInputStream(bytes)); }
private Source convertResponse(Element responseElement) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Serializer serializer = createSerializer(os); Document document = responseElement.getDocument(); if (document == null) { document = new Document(responseElement); } serializer.write(document); byte[] bytes = os.toByteArray(); return new StreamSource(new ByteArrayInputStream(bytes)); }
private static void printDocument(Document document) { Serializer serializer = new Serializer(System.out); serializer.setLineSeparator("\n"); serializer.setIndent(2); try { serializer.write(document); } catch (IOException e) { throw new RuntimeException(e); } } }
private static void printDocument(Document document) { Serializer serializer = new Serializer(System.out); serializer.setLineSeparator("\n"); serializer.setIndent(2); try { serializer.write(document); } catch (IOException e) { throw new RuntimeException(e); } } }
/** convenience method to serialize the element. * * @param os * @param indent to indent lines by (non-zero may muck up whitespace) * @throws IOException */ public void serialize(OutputStream os, int indent) throws IOException { Document doc = new Document((CMLElement)this.copy()); Serializer serializer = new Serializer(os); serializer.write(doc); }
public static void format(OutputStream os, Document doc) throws Exception { Serializer serializer = new Serializer(os,"ISO-8859-1"); serializer.setIndent(4); serializer.setMaxLength(60); serializer.write(doc); serializer.flush(); } public static void
@Test public void writeNamespacesUnchanged() throws ValidityException, ParsingException, IOException { Document pom = new Builder().build(new File(new File("src/it/upgrade"), "pom.xml")); Serializer s = new StickySerializer(new FileOutputStream(new File("target/tmp.xml")), "UTF-8"); s.write(pom); } }
@Test public void writeNamespacesUnchanged() throws ValidityException, ParsingException, IOException { Document pom = new Builder().build(new File(new File("src/it/update"), "pom.xml")); Serializer s = new StickySerializer(new FileOutputStream(new File("target/tmp.xml")), "UTF-8"); s.write(pom); } }
public static void xmlPrint(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); ser.setIndent(2); ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }