List of usage examples for org.dom4j.io OutputFormat setExpandEmptyElements
public void setExpandEmptyElements(boolean expandEmptyElements)
This will set whether empty elements are expanded from <tagName>
to <tagName></tagName>
.
From source file:eu.planets_project.pp.plato.action.workflow.ValidatePlanAction.java
License:Open Source License
/** * reads the executable preservation plan and formats it. * /*from w ww . ja v a 2 s. c o m*/ */ private String formatExecutablePlan(String executablePlan) { if (executablePlan == null || "".equals(executablePlan)) { return ""; } try { Document doc = DocumentHelper.parseText(executablePlan); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewlines(true); format.setTrimText(true); format.setIndent(" "); format.setExpandEmptyElements(false); format.setNewLineAfterNTags(20); XMLWriter writer = new XMLWriter(sw, format); writer.write(doc); writer.close(); return sw.toString(); } catch (DocumentException e) { return ""; } catch (IOException e) { return ""; } }
From source file:nl.nn.adapterframework.util.XmlUtils.java
License:Apache License
public static String canonicalize(String input) throws DocumentException, IOException { if (StringUtils.isEmpty(input)) { return null; }// w w w . j a v a2 s .c o m org.dom4j.Document doc = DocumentHelper.parseText(input); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setExpandEmptyElements(true); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); return sw.toString(); }
From source file:nl.tue.gale.common.GaleUtil.java
License:Open Source License
public static String serializeXML(Element element) { StringWriter out = new StringWriter(); OutputFormat of = new OutputFormat(); of.setExpandEmptyElements(true); XMLWriter writer = new XMLWriter(out, of) { @Override//from w w w .j ava2 s . c o m protected void writeEmptyElementClose(String qualifiedName) throws IOException { if (omitCloseSet.contains(qualifiedName.toUpperCase())) { writer.write(" />"); } else { super.writeEmptyElementClose(qualifiedName); } } }; try { writer.write(element); writer.flush(); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException("unable to serialize XML: " + e.getMessage()); } return out.toString(); }
From source file:org.dentaku.gentaku.tools.cgen.plugin.GenGenPlugin.java
License:Apache License
private void prettyPrint(Document document, Writer writer) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(encoding);//from w w w. jav a 2s . c o m format.setSuppressDeclaration(false); format.setExpandEmptyElements(false); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(document); xmlWriter.flush(); }
From source file:org.dentaku.gentaku.tools.cgen.visitor.JellyTemplateGeneratingVisitor.java
License:Apache License
public void handleElement(Element element) throws VisitorException { if (element.getParent().getName().equals("schema")) { QName rootName = DocumentFactory.getInstance().createQName("jelly", "j", "jelly:core"); Branch parent = DocumentHelper.createDocument().addElement(rootName).addNamespace("x", "jelly:xml"); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(getEncoding()); format.setSuppressDeclaration(false); format.setExpandEmptyElements(false); pushParent(parent.addElement(element.getName())); for (Iterator it = element.elementIterator(); it.hasNext();) { visit((Element) it.next()); }//from ww w . j a v a 2 s . c om popParent(); try { String filename = element.getName() + ".jelly"; Writer out = new FileWriter(new File(getRootDir(), filename)); final XMLWriter xmlWriter = new XMLWriter(out, format); xmlWriter.setEscapeText(false); xmlWriter.write(parent); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { throw new VisitorException("Exception occurred when running Jelly", e); } topLevelElements.put(element.getName(), element); } else { String refName = element.attributeValue("ref"); if (refName != null) { Branch parent = getCurrentParent(); // create an include QName qName = DocumentFactory.getInstance().createQName("import", "j", "jelly:core"); parent.addElement(qName).addAttribute("uri", refName + ".jelly").addAttribute("inherit", "true"); } } }
From source file:org.dentaku.gentaku.tools.cgen.xmi.XMIGenTask.java
License:Apache License
private void writeFile(Branch document, File file) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(System.getProperty("file.encoding")); format.setSuppressDeclaration(false); format.setExpandEmptyElements(false); Writer out = new FileWriter(file); final XMLWriter xmlWriter = new XMLWriter(out, format); xmlWriter.setEscapeText(false);//from www.jav a2 s . c o m xmlWriter.write(document); xmlWriter.flush(); xmlWriter.close(); }
From source file:org.hightides.annotations.util.SpringXMLUtil.java
License:Apache License
/** * Private helper to save XML document./*from www .ja va 2 s . com*/ * @param filename * @param doc * @param backup * @return */ private static boolean saveXMLDocument(String filename, Document doc, boolean backup) { // copy the target to backup folder if (backup) FileUtil.backupFile(filename); // overwrite the target OutputFormat format = OutputFormat.createPrettyPrint(); format.setExpandEmptyElements(false); format.setIndentSize(4); format.setNewLineAfterDeclaration(true); XMLWriter out; try { out = new XMLWriter(new FileWriter(filename), format); out.write(doc); out.flush(); out.close(); return true; } catch (IOException e) { _log.info("Failed to write to output filename [" + filename + "]", e); return false; } }
From source file:org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction.java
License:Open Source License
protected String getFormattedDocument(Document doc, boolean compact, boolean supressDecl) { OutputFormat format = compact ? OutputFormat.createCompactFormat() : OutputFormat.createPrettyPrint(); format.setSuppressDeclaration(supressDecl); format.setEncoding(ENCODING);/*w w w . j av a 2s. c o m*/ format.setExpandEmptyElements(false); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); try { writer.write(doc); } catch (IOException e) { e.printStackTrace(); } return stringWriter.toString(); }
From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java
License:Open Source License
private String getFormattedDocument(Document doc, boolean compact) { OutputFormat format = compact ? OutputFormat.createCompactFormat() : OutputFormat.createPrettyPrint(); // format.setEncoding("iso-8859-1"); format.setEncoding("UTF-8"); format.setExpandEmptyElements(false); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); try {/*from www .j a v a 2 s . c o m*/ writer.write(doc); } catch (IOException e) { e.printStackTrace(); } return stringWriter.toString(); }
From source file:org.infoglue.cms.util.dom.DOMBuilder.java
License:Open Source License
public String getFormattedDocument(Document doc, boolean compact, boolean supressDecl, String encoding) { OutputFormat format = compact ? OutputFormat.createCompactFormat() : OutputFormat.createPrettyPrint(); format.setSuppressDeclaration(supressDecl); format.setEncoding(encoding);//from ww w. j av a 2 s . c om format.setExpandEmptyElements(false); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); try { writer.write(doc); } catch (IOException e) { e.printStackTrace(); } return stringWriter.toString(); }