本文整理了Java中org.jdom.output.Format.setExpandEmptyElements()
方法的一些代码示例,展示了Format.setExpandEmptyElements()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Format.setExpandEmptyElements()
方法的具体详情如下:
包路径:org.jdom.output.Format
类名称:Format
方法名:setExpandEmptyElements
[英]This will set whether empty elements are expanded from <tagName/>
to <tagName></tagName>
.
[中]这将设置是否将空元素从<tagName/>
扩展到<tagName></tagName>
。
代码示例来源:origin: org.xwiki.commons/xwiki-commons-xml
@Override
protected void printElement(Writer out, Element element, int level, NamespaceStack namespaces)
throws IOException
{
// We override the code from the super class to not expand some empty elements.
boolean currentFormatPolicy = currentFormat.getExpandEmptyElements();
try {
String elementName = element.getName();
for (String name : OMIT_ELEMENT_EXPANDING_SET) {
if (name.equals(elementName)) {
// We do not expand this empty element
currentFormat.setExpandEmptyElements(false);
break;
}
}
// Call the method from the super class
super.printElement(out, element, level, namespaces);
} finally {
// Reset the format
currentFormat.setExpandEmptyElements(currentFormatPolicy);
}
}
}
代码示例来源:origin: org.kathrynhuxtable.maven.plugins/htmlfilter-site-maven-plugin
/**
* Get the element contents as a String.
*
* @param element the element.
*
* @return the element contents.
*/
private String getElementContentsAsText(Element element) {
StringBuilder text = new StringBuilder();
HTMLOutputter writer = new HTMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.TRIM_FULL_WHITE)
.setExpandEmptyElements(true));
List<Element> children = getChildren(element);
if (children.size() == 0) {
return element.getText();
}
for (Element child : children) {
StringWriter sw = new StringWriter();
try {
writer.output(child, sw);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
text.append(sw);
}
return text.toString();
}
代码示例来源:origin: info.magnolia/magnolia-core
public static InputStream getElementAsStream(String fileName, String nodePath) {
String xpathExpr = BootstrapFileUtil.getXPathNodeQueryString(nodePath);
Element ele = getElementFromXPath(fileName, xpathExpr);
if (ele == null) {
throw new RuntimeException("Node path " + nodePath + " doesn't exist in bootstrap file " + fileName);
}
ele.detach();
Document doc = new Document(ele);
Format format = Format.getRawFormat();
format.setExpandEmptyElements(true);
XMLOutputter outputter = new XMLOutputter(format);
byte[] bytes;
try {
bytes = outputter.outputString(doc).getBytes(format.getEncoding());
} catch (UnsupportedEncodingException e) {
bytes = outputter.outputString(doc).getBytes();
}
return new ByteArrayInputStream(bytes);
}
代码示例来源:origin: org.ow2.easywsdl/easywsdl-tool-xsd2xml
@Override
public String printXml( org.jdom.Element element ) {
Format formatter = Format.getPrettyFormat().setIndent( "\t" ).setExpandEmptyElements( true ).setEncoding( "UTF-8" );
return printXml( element, formatter );
}
代码示例来源:origin: Ekryd/sortpom
private Format createPrettyFormat() {
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(expandEmptyElements);
prettyFormat.setEncoding(encoding);
prettyFormat.setLineSeparator("\n");
prettyFormat.setIndent(indentCharacters);
return prettyFormat;
}
代码示例来源:origin: com.google.code.sortpom/maven-sortpom-sorter
private Format createPrettyFormat() {
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(expandEmptyElements);
prettyFormat.setEncoding(encoding);
prettyFormat.setLineSeparator("\n");
prettyFormat.setIndent(indentCharacters);
return prettyFormat;
}
代码示例来源:origin: javasoze/meaningfulweb
public static String toXml(Document doc, String encoding) {
String htmlstr = null;
try {
// write out the xml to a string
StringWriter writer = new StringWriter();
Format format = Format.getPrettyFormat();
format.setExpandEmptyElements(true);
format.setOmitDeclaration(true);
format.setEncoding(encoding);
XMLOutputter out = new XMLOutputter(format);
out.output(doc, writer);
// xml processing will escape out certain characters that are legal in
// html we convert those characters back here to html entity codes instead
// of xml entitity codes. We also replace unicodeish characters to their
// html entity equivalents. This helps in displaying with people don't
// have the correct charset packs installed
String output = StringEscapeUtils.unescapeXml(writer.toString());
htmlstr = StringEscapeUtils.unescapeHtml(output);
writer.close();
}
catch (IOException e) {
// do nothing
}
return htmlstr;
}
代码示例来源:origin: javasoze/meaningfulweb
public static String toHtml(Element elem, String encoding) {
String htmlstr = null;
try {
// write out the xml to a string
StringWriter writer = new StringWriter();
Format format = Format.getPrettyFormat();
format.setExpandEmptyElements(true);
format.setOmitDeclaration(true);
format.setEncoding(encoding);
XMLOutputter out = new XMLOutputter(format);
out.output(elem, writer);
// xml processing will escape out certain characters that are legal in
// html we convert those characters back here to html entity codes instead
// of xml entitity codes. We also replace unicodeish characters to their
// html entity equivalents. This helps in displaying with people don't
// have the correct charset packs installed
String output = StringEscapeUtils.unescapeXml(writer.toString());
htmlstr = StringEscapeUtils.unescapeHtml(output);
writer.close();
}
catch (IOException e) {
// do nothing
}
return htmlstr;
}
代码示例来源:origin: bcdev/beam
public String getAsXML() {
// following lines uses the old JDOM jar
// xmlOutputter.setIndent(true);
// xmlOutputter.setIndent(" ");
// xmlOutputter.setNewlines(true);
// xmlOutputter.setExpandEmptyElements(false);
// xmlOutputter.setOmitEncoding(true);
// xmlOutputter.setOmitDeclaration(true);
// xmlOutputter.setTextNormalize(true);
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(false);
prettyFormat.setOmitEncoding(true);
prettyFormat.setOmitDeclaration(true);
prettyFormat.setTextMode(Format.TextMode.NORMALIZE);
final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
return xmlOutputter.outputString(createRootTree("class name list template"));
}
代码示例来源:origin: bcdev/beam
private static String toXMLString(Element metadataElement) {
// following lines uses the old JDOM jar
// xmlOutputter.setIndent(true);
// xmlOutputter.setIndent(" ");
// xmlOutputter.setNewlines(true);
// xmlOutputter.setExpandEmptyElements(false);
// xmlOutputter.setOmitEncoding(true);
// xmlOutputter.setOmitDeclaration(true);
// xmlOutputter.setTextNormalize(false);
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(false);
prettyFormat.setOmitEncoding(true);
prettyFormat.setOmitDeclaration(true);
prettyFormat.setTextMode(Format.TextMode.NORMALIZE);
final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
final String xml = xmlOutputter.outputString(metadataElement);
return xml;
}
}
代码示例来源:origin: javasoze/meaningfulweb
format.setExpandEmptyElements(true);
format.setOmitDeclaration(true);
format.setEncoding(encoding);
代码示例来源:origin: org.xwiki.platform/xwiki-core-xml
format.setExpandEmptyElements(true);
代码示例来源:origin: bcdev/beam
private static String getXML(Element metadataElement) {
// following lines uses the old JDOM jar
// xmlOutputter.setIndent(true);
// xmlOutputter.setIndent(" ");
// xmlOutputter.setNewlines(true);
// xmlOutputter.setExpandEmptyElements(false);
// xmlOutputter.setOmitEncoding(true);
// xmlOutputter.setOmitDeclaration(true);
// xmlOutputter.setTextNormalize(false);
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(false);
prettyFormat.setOmitEncoding(true);
prettyFormat.setOmitDeclaration(true);
prettyFormat.setTextMode(Format.TextMode.PRESERVE);
final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
final String xml = xmlOutputter.outputString(metadataElement);
return xml;
}
代码示例来源:origin: bcdev/beam
@SuppressWarnings({"UnusedDeclaration"})
private void printDocument(Document document) {
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(false);
prettyFormat.setOmitEncoding(true);
prettyFormat.setOmitDeclaration(true);
prettyFormat.setTextMode(Format.TextMode.NORMALIZE);
final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
final String xml = xmlOutputter.outputString(document);
System.out.println(xml);
}
代码示例来源:origin: info.magnolia/magnolia-module-mail
format.setExpandEmptyElements(true);
代码示例来源:origin: org.xwiki.commons/xwiki-commons-xml
/**
* @param document the W3C Document to transform into a String
* @param omitDeclaration whether the XML declaration should be printed or not
* @param omitDoctype whether the document type should be printed or not
* @return the XML as a String
*/
public static String toString(Document document, boolean omitDeclaration, boolean omitDoctype)
{
// Note: We don't use javax.xml.transform.Transformer since it prints our valid XHTML as HTML which is not
// XHTML compliant. For example it transforms our "<hr/>" into "<hr>.
DOMBuilder builder = new DOMBuilder();
org.jdom.Document jdomDoc = builder.build(document);
Format format = Format.getRawFormat();
// Force newlines to use \n since otherwise the default is \n\r.
// See http://www.jdom.org/docs/apidocs/org/jdom/output/Format.html#setLineSeparator(java.lang.String)
format.setLineSeparator("\n");
// Make sure all elements are expanded so that they can also be rendered fine in browsers that only support
// HTML.
format.setExpandEmptyElements(true);
format.setOmitDeclaration(omitDeclaration);
XMLOutputter outputter = new XWikiXMLOutputter(format, omitDoctype);
String result = outputter.outputString(jdomDoc);
return result;
}
内容来源于网络,如有侵权,请联系作者删除!