当前位置: 首页>>代码示例>>Java>>正文


Java OutputFormat.setExpandEmptyElements方法代码示例

本文整理汇总了Java中org.dom4j.io.OutputFormat.setExpandEmptyElements方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.setExpandEmptyElements方法的具体用法?Java OutputFormat.setExpandEmptyElements怎么用?Java OutputFormat.setExpandEmptyElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dom4j.io.OutputFormat的用法示例。


在下文中一共展示了OutputFormat.setExpandEmptyElements方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printXML

import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
 * 打印XML
 *
 * @param document
 */
protected void printXML(Document document) {
    if (log.isInfoEnabled()) {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setExpandEmptyElements(true);
        format.setSuppressDeclaration(true);
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, format);
        try {
            writer.write(document);
            log.info(stringWriter.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:minlia-projects,项目名称:minlia-iot,代码行数:21,代码来源:AbstractApiComponent.java

示例2: testExpandEmptyElements

import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
@Test
public void testExpandEmptyElements() throws IOException {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("root");
    Element id = root.addElement("id");
    id.addText("1");

    root.addElement("empty");

    OutputFormat xmlFormat = new OutputFormat();
    // OutputFormat.createPrettyPrint();
    xmlFormat.setSuppressDeclaration(true);
    xmlFormat.setEncoding("UTF-8");
    // If this is true, elements without any child nodes
    // are output as <name></name> instead of <name/>.
    xmlFormat.setExpandEmptyElements(true);


    StringWriter out = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(out, xmlFormat);
    xmlWriter.write(document);
    xmlWriter.close();

    assertEquals("<root><id>1</id><empty></empty></root>", out.toString());
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:26,代码来源:Dom4jTest.java

示例3: formatXml

import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
 * Returns the given xml document as nicely formated string.
 * 
 * @param node
 *            The xml document.
 * @return the formated xml as string.
 */
private static String formatXml(Node node) {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setIndentSize(4);
    format.setTrimText(true);
    format.setExpandEmptyElements(true);
    
    StringWriter stringWriter = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(stringWriter, format);
    try {
        xmlWriter.write(node);
        xmlWriter.flush();
    } catch (IOException e) {
        // this should never happen
        throw new RuntimeException(e);
    }

    return stringWriter.getBuffer().toString();
}
 
开发者ID:kkrugler,项目名称:yalder,代码行数:26,代码来源:WikipediaCrawlTool.java


注:本文中的org.dom4j.io.OutputFormat.setExpandEmptyElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。