private static XMLOutputter xmlOutputer() { Format format = Format.getPrettyFormat().setEncoding("utf-8").setLineSeparator("\n"); return new XMLOutputter(format); }
/** * This will set the newline separator sequence. * <p> * This method differes from {@link #setLineSeparator(String)} slightly in * that, to disable end-of-line processing you should call: * <pre> * Format.setLinewSeparator(LineSeparator.NONE); * </pre> * * @see #setLineSeparator(String) for comprehensive notes. * * @param separator {@link LineSeparator} line separator to us * @return a pointer to this Format for chaining * @since JDOM2 */ public Format setLineSeparator(LineSeparator separator) { return setLineSeparator(separator == null ? STANDARD_LINE_SEPARATOR : separator.value()); }
public NcMLWriter() { this.namespace = ncmlDefaultNamespace; this.xmlFormat = Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX); this.writeVariablesPredicate = writeMetadataVariablesPredicate; }
p.println(""); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.getFormat().setLineSeparator(System.lineSeparator()); try { out.output((Element) value, p);
/** * Method write * * @param project * @param writer * @param document */ public void write( Model project, Document document, OutputStreamWriter writer ) throws java.io.IOException { Format format = Format.getRawFormat(); format.setEncoding( writer.getEncoding() ).setLineSeparator( System.getProperty( "line.separator" ) ); write( project, document, writer, format ); } // -- void write(Model, Document, OutputStreamWriter)
/** * Writes the specified JDOM element to the XML file specified by filename. * The file will use UTF-8 encoding and has 4-space indentation. * * @param eRoot root element of the XML document * @param filename filename of the XML file to create * @throws IOException */ public static void writeXMLFile(Element eRoot, String filename) throws IOException { Document document = new Document(eRoot); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setLineSeparator(System.getProperty("line.separator")); format.setIndent(" "); outputter.setFormat(format); // FileWriter can't be used here, because default encoding on Win32 isn't UTF-8 try (OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")) { outputter.output(document, osWriter); osWriter.flush(); } } }
/** * Returns a string containing the XML content of a KAFDocument object. */ static String kafToStr(KAFDocument kaf) { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX)); // out.getFormat().setTextMode(Format.TextMode.PRESERVE); Document jdom = KAFToDOM(kaf); return out.outputString(jdom); }
docFormat.setLineSeparator(System.getProperty("line.separator")); XMLOutputter outputter = new XMLOutputter(docFormat); outputter.output(new Document(rootElement), writer);
/** Returns a string containing the XML content of a KAFDocument object. */ static String kafToStr(KAFDocument kaf) { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX).setTextMode(Format.TextMode.TRIM_FULL_WHITE)); Document jdom = KAFToDOM(kaf); return out.outputString(jdom); }
private void writeXmlWithExcludes(InputStream inputStream, OutputStream outputStream, Set<String> namespacePrefixes) throws IOException, JDOMException { SAXBuilder saxBuilder = new SAXBuilder(); Document doc = saxBuilder.build(inputStream); Set<String> namespacePrefixesActuallyUsed = new HashSet<>(); applyXmlExcludes(doc.getRootElement(), "", namespacePrefixesActuallyUsed); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat() .setIndent(" ") .setLineSeparator(LineSeparator.UNIX)); outputter.setXMLOutputProcessor(new OneAttributePerLineXmlProcessor(namespacePrefixes, namespacePrefixesActuallyUsed)); outputter.output(doc, outputStream); outputStream.flush(); }
/** * Writes the internal xml after validation to file. * * @param localDoc * the local doc * @param outFilename * the output file name */ public static void writeInternalXmlToFile(Document localDoc, String outFilename) { final PrintWriter writer = FileUtils.getWriter(outFilename); final XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent(" "); format.setLineSeparator("\n"); outputter.setFormat(format); outputter.setFormat(format); try { LOG.info(" write internal xml after validation to file \"" + outFilename + "\""); outputter.output(localDoc, writer); } catch (final Exception e) { e.printStackTrace(); } }
/** * {@inheritDoc} */ public String getString() throws IOException { m_document.setContext( m_context ); CustomXMLOutputProcessor processor = new CustomXMLOutputProcessor(); XMLOutputter output = new XMLOutputter(processor); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); String result = out.toString(); return result; } }
/** * {@inheritDoc} */ public String getString() throws IOException { Element rootElement = m_document.getRootElement(); processChildren( rootElement ); m_document.setContext( m_context ); XMLOutputter output = new XMLOutputter(); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); return out.toString(); } }
format.setLineSeparator( ls ); XMLOutputter out = new XMLOutputter( format ); out.output( document.getRootElement(), writer );
prettyFormatter.setLineSeparator(System.getProperty("line.separator")); XMLOutputter sortie = new XMLOutputter(prettyFormatter);
/** * Method write * * @param project * @param stream * @param document * @deprecated */ public void write( Model project, Document document, OutputStream stream ) throws java.io.IOException { updateModel( project, "project", new Counter( 0 ), document.getRootElement() ); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent( " " ).setLineSeparator( System.getProperty( "line.separator" ) ); outputter.setFormat( format ); outputter.output( document, stream ); } // -- void write(Model, Document, OutputStream)
prettyFormatter.setLineSeparator(System.getProperty("line.separator")); XMLOutputter sortie = new XMLOutputter(prettyFormatter);
final Format format = Format.getRawFormat(); format.setTextMode( Format.TextMode.PRESERVE ); format.setLineSeparator( "" ); outputter.setFormat( format ); outputter.output( doc, writer );
static public void prettyPrint() throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(); doc = builder.build("C:/docs/bufr/wmo/Code-FlagTables-11-2007.xml"); Format pretty = Format.getPrettyFormat(); String sep = pretty.getLineSeparator(); String ind = pretty.getIndent(); String mine = "\r\n"; pretty.setLineSeparator(mine); // wierd - cant pretty print ??!! XMLOutputter fmt = new XMLOutputter(pretty); Writer pw = new FileWriter("C:/docs/bufr/wmo/wordNice.txt"); fmt.output(doc, pw); } catch (JDOMException e) { throw new IOException(e.getMessage()); } }
format.setOmitDeclaration( false ); format.setIndent( "\t" ); format.setLineSeparator( LineSeparator.CRNL );