/** {@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(); }
@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); } } }
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"); }
public void write(final OutputStream os, final Charset charset) throws IOException { if (doc == null) throw new IllegalStateException("Call parse() before calling this method!"); // Display output: Serializer serializer = new Serializer(os, charset.name()); serializer.setIndent(4); serializer.write(doc); }
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); } } }
/** * Marshall the data in the enclosed SWORD Entry. * * @return The string representation. Null if there was an error. */ public String marshall() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = new Serializer(stream, "UTF-8"); serializer.setIndent(3); if (entry != null) { Document doc = new Document(entry.marshall()); serializer.write(doc); log.info(stream.toString()); return stream.toString(); } } catch (IOException ex) { log.error(ex.getMessage()); } return null; // default return value. }
/** {@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(); }
public static String graphToXml(Graph graph) { Document document = new Document(convertToXml(graph)); OutputStream out = new ByteArrayOutputStream(); Serializer serializer = new Serializer(out); serializer.setLineSeparator("\n"); serializer.setIndent(2); try { serializer.write(document); } catch (IOException e) { throw new RuntimeException(e); } return out.toString(); }
/** * Marshall the data in the Service element and generate a String * representation. The returned string is UTF-8 format. * * @return A string of XML, or <code>null</code> if there was an error * marshalling the data. */ public String marshall() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = new Serializer(stream, "UTF-8"); serializer.setIndent(3); //serializer.setMaxLength(64); Document doc = new Document(service.marshall()); serializer.write(doc); return stream.toString(); } catch (IOException ex) { System.err.println(ex); } return null; }
/** * Marshall the data in the Service element and generate a String * representation. The returned string is UTF-8 format. * * @return A string of XML, or <code>null</code> if there was an error * marshalling the data. */ public String marshall() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = new Serializer(stream, "UTF-8"); serializer.setIndent(3); //serializer.setMaxLength(64); Document doc = new Document(service.marshall()); serializer.write(doc); return stream.toString(); } catch (IOException ex) { System.err.println(ex); } return null; }
/** * * @param doc * @return */ public static String serialize(final Node doc) throws CouldNotProcessException { final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); final Serializer ser = new Serializer(outStream); try { ser.setIndent(3); ser.write(doc.getDocument()); return outStream.toString(); } catch (IOException ex) { throw new CouldNotProcessException("Couldn't transform doc to prettyXMLString. Returning old document.", ex); } }
/** * Marshall the data in the Service element and generate a String * representation. The returned string is UTF-8 format. * * @return A string of XML, or <code>null</code> if there was an error * marshalling the data. */ public String marshall() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = new Serializer(stream, "UTF-8"); serializer.setIndent(3); //serializer.setMaxLength(64); Document doc = new Document(service.marshall()); serializer.write(doc); return stream.toString(); } catch (IOException ex) { System.err.println(ex); } return null; }
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
public void actionPerformed(ActionEvent e) { try { File outfile = EditorUtils.getSaveFile("bayesim", "xml", this.bayesImEditor, false, "Save Bayes IM as XML..."); BayesIm bayesIm = bayesImEditor.getWizard().getBayesIm(); FileOutputStream out = new FileOutputStream(outfile); Element element = BayesXmlRenderer.getElement(bayesIm); Document document = new Document(element); Serializer serializer = new Serializer(out); serializer.setLineSeparator("\n"); serializer.setIndent(2); serializer.write(document); out.close(); } catch (IOException e1) { throw new RuntimeException(e1); } } }
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(); }
/** * Displays the output of all annotators in XML format. * @param annotation Contains the output of all annotators * @param os The output stream * @throws IOException */ public void xmlPrint(Annotation annotation, OutputStream os) throws IOException { Document xmlDoc = annotationToDoc(annotation); Serializer ser = new Serializer(os, "UTF-8"); ser.setIndent(2); ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
/** debug. * * @param os * @param indent * @throws IOException */ public void debug(OutputStream os, int indent) throws IOException { Document document; Node parent = this.getParent(); if (parent instanceof Document) { document = (Document) parent; } else { CMLElement copyElem = new CMLElement(this); document = new Document(copyElem); } Serializer serializer = new Serializer(os); serializer.setIndent(indent); // if (indent == 0) { // serializer.setLineSeparator("\r\n"); // } serializer.write(document); }
/** * Write a collection of specifications to an output stream. * * @param specifications * the specifications * @param out * the output stream */ public void write(Collection<Specification> specifications, OutputStream out) { nu.xom.Element eSpecs = new nu.xom.Element("specifications", NS); for (Specification spec : specifications) { nu.xom.Element eSpec = toElement(spec); eSpecs.appendChild(eSpec); } nu.xom.Document doc = new nu.xom.Document(eSpecs); try { Serializer serializer = new Serializer(out); serializer.setIndent(2); serializer.setMaxLength(2000); serializer.write(doc); serializer.flush(); } catch (IOException ex) { System.out.println(ex + " " + out); } }