当前位置: 首页>>代码示例>>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;未经允许,请勿转载。