本文整理汇总了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();
}
}
}
示例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());
}
示例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();
}
示例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, "");
}
示例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);
}
示例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;
}