本文整理匯總了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;
}