當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。