當前位置: 首頁>>代碼示例>>Java>>正文


Java OutputFormat.setSuppressDeclaration方法代碼示例

本文整理匯總了Java中org.dom4j.io.OutputFormat.setSuppressDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputFormat.setSuppressDeclaration方法的具體用法?Java OutputFormat.setSuppressDeclaration怎麽用?Java OutputFormat.setSuppressDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dom4j.io.OutputFormat的用法示例。


在下文中一共展示了OutputFormat.setSuppressDeclaration方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: testEscapeXML

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
public void testEscapeXML() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    OutputFormat format = new OutputFormat(null, false, "ISO-8859-2");
    format.setSuppressDeclaration(true);

    XMLWriter writer = new XMLWriter(os, format);

    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement("root");
    root.setText("bla &#c bla");

    writer.write(document);

    String result = os.toString();

    Document doc2 = DocumentHelper.parseText(result);
    doc2.normalize(); 
}
 
開發者ID:regestaexe,項目名稱:bygle-ldp,代碼行數:19,代碼來源:XMLBuilder.java

示例4: xmlToString

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
private String xmlToString(Document xml) throws IOException {
    String lineSeparator = System.getProperty("line.separator");
    OutputFormat format = OutputFormat.createCompactFormat();
    format.setIndentSize(4);
    format.setNewlines(true);
    format.setLineSeparator(lineSeparator);
    format.setSuppressDeclaration(true);
    StringWriter result = new StringWriter();
    XMLWriter writer = new XMLWriter(result, format);
    writer.write(xml);
    return result.toString().replaceFirst(lineSeparator, "");
}
 
開發者ID:SimY4,項目名稱:xpath-to-xml,代碼行數:13,代碼來源:XmlBuilderTest.java

示例5: setUp

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
protected void setUp() throws Exception {
    super.setUp();

    Dom4JDriver driver = new Dom4JDriver();

    OutputFormat format = OutputFormat.createCompactFormat();
    format.setTrimText(false);
    format.setSuppressDeclaration(true);
    driver.setOutputFormat(format);

    out = new StringWriter();
    writer = driver.createWriter(out);
}
 
開發者ID:x-stream,項目名稱:xstream,代碼行數:14,代碼來源:Dom4JXmlWriterTest.java

示例6: toWorkflow

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
 * Transform the Graph into an workflow xml definition
 * @param jobname the job name of Oozie job, can't be null
 * @return workflow xml
 */
public String toWorkflow(String jobname) {
	Namespace xmlns = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri
	QName qName = QName.get("workflow-app", xmlns); // your root element's name
	Element workflow = DocumentHelper.createElement(qName);
	Document xmldoc = DocumentHelper.createDocument(workflow);
	// Create workflow root
	workflow.addAttribute("xmlns", "uri:oozie:workflow:0.4");
	// <workflow-app name='xxx'></workflow-app>
	if (jobname == null || "".equals(jobname))
		workflow.addAttribute("name", "Not specified");
	else
		workflow.addAttribute("name", jobname);

	Queue<NodeDef> que = new LinkedList<NodeDef>();
	que.add(start);

	while (!que.isEmpty()) {
		NodeDef cur = que.remove();

		cur.append2XML(workflow);

		for (NodeDef toNode : cur.getOutNodes()) {
			toNode.delInNode(cur);
			if (toNode.getInDegree() == 0)
				que.add(toNode);
		}
	}

	// Set XML document format
	OutputFormat outputFormat = OutputFormat.createPrettyPrint();
	// Set XML encoding, use the specified encoding to save the XML document to the string, it can be specified GBK or ISO8859-1
	outputFormat.setEncoding("UTF-8");
	outputFormat.setSuppressDeclaration(true); // Whether generate xml header
	outputFormat.setIndent(true); // Whether set indentation
	outputFormat.setIndent("    "); // Implement indentation with four spaces
	outputFormat.setNewlines(true); // Set whether to wrap

	try {
		// stringWriter is used to save xml document
		StringWriter stringWriter = new StringWriter();
		// xmlWriter is used to write XML document to string(tool)
		XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat);
		
		// Write the created XML document into the string
		xmlWriter.write(xmldoc);

		xmlWriter.close();

		System.out.println( stringWriter.toString().trim());
		// Print the string, that is, the XML document
		return stringWriter.toString().trim();

	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return null;
}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:63,代碼來源:WFGraph.java


注:本文中的org.dom4j.io.OutputFormat.setSuppressDeclaration方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。