本文整理了Java中org.dom4j.io.OutputFormat.setIndent()
方法的一些代码示例,展示了OutputFormat.setIndent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OutputFormat.setIndent()
方法的具体详情如下:
包路径:org.dom4j.io.OutputFormat
类名称:OutputFormat
方法名:setIndent
[英]This will set the indent String
to use; this is usually a String
of empty spaces. If you pass null, or the empty string (""), then no indentation will happen. Default: none (null)
[中]这将设置要使用的缩进String
;这通常是一个String
的空白空间。如果传递null或空字符串(“”),则不会发生缩进。默认值:无(空)
代码示例来源:origin: stackoverflow.com
//Prepare JAXB objects
JAXBContext jc = JAXBContext.newInstance("jaxb.package");
Marshaller m = jc.createMarshaller();
//Define an output file
File output = new File("test.xml");
//Create a filter that will remove the xmlns attribute
NamespaceFilter outFilter = new NamespaceFilter(null, false);
//Do some formatting, this is obviously optional and may effect performance
OutputFormat format = new OutputFormat();
format.setIndent(true);
format.setNewlines(true);
//Create a new org.dom4j.io.XMLWriter that will serve as the
//ContentHandler for our filter.
XMLWriter writer = new XMLWriter(new FileOutputStream(output), format);
//Attach the writer to the filter
outFilter.setContentHandler(writer);
//Tell JAXB to marshall to the filter which in turn will call the writer
m.marshal(myJaxbObject, outFilter);
代码示例来源:origin: webx/citrus
/** 输出DOM。 */
public static void writeDocument(Document doc, Writer writer, String charset) throws IOException {
charset = defaultIfEmpty(trimToNull(charset), "UTF-8");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(charset);
format.setIndent(true);
format.setIndentSize(4);
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(doc);
xmlWriter.flush();
}
代码示例来源:origin: stackoverflow.com
Document doc = ...;
OutputFormat format = new OutputFormat(doc);
format.setIndenting(true);
format.setIndent(2);
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(doc);
代码示例来源:origin: webx/citrus
/** 输出DOM。 */
public static void writeDocument(Document doc, Writer writer, String charset) throws IOException {
charset = defaultIfEmpty(trimToNull(charset), "UTF-8");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(charset);
format.setIndent(true);
format.setIndentSize(4);
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(doc);
xmlWriter.flush();
}
代码示例来源:origin: mulesoft/mule
private String renderSchema(Schema schema) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class);
Marshaller marshaller = jaxbContext.createMarshaller();
NamespaceFilter outFilter = new NamespaceFilter(CORE_PREFIX, CORE_NAMESPACE, true);
OutputFormat format = new OutputFormat();
format.setIndent(true);
format.setNewlines(true);
StringWriter sw = new StringWriter();
XMLWriter writer = new XMLWriter(sw, format);
outFilter.setContentHandler(writer);
marshaller.marshal(schema, outFilter);
return sw.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: stackoverflow.com
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer outxml = new FileWriter(new File("out.xml"));
XMLSerializer serializer = new XMLSerializer(outxml, format);
serializer.serialize(document);
代码示例来源:origin: webx/citrus
/** 输出DOM。 */
public static void writeDocument(Document doc, Writer writer, String charset) throws IOException {
charset = defaultIfEmpty(trimToNull(charset), "UTF-8");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(charset);
format.setIndent(true);
format.setIndentSize(4);
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(doc);
xmlWriter.flush();
}
代码示例来源:origin: org.dom4j/dom4j
/**
* A static helper method to create the default compact format. This format
* does not have any indentation or newlines after an alement and all other
* whitespace trimmed
*
* @return DOCUMENT ME!
*/
public static OutputFormat createCompactFormat() {
OutputFormat format = new OutputFormat();
format.setIndent(false);
format.setNewlines(false);
format.setTrimText(true);
return format;
}
}
代码示例来源:origin: stackoverflow.com
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer outxml = new FileWriter(new File("out.xml"));
XMLSerializer serializer = new XMLSerializer(outxml, format);
serializer.serialize(document);
代码示例来源:origin: org.dom4j/dom4j
setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
setIndent(args[++i]);
} else if (args[i].equals("-indentSize")) {
setIndentSize(Integer.parseInt(args[++i]));
代码示例来源:origin: org.dom4j/dom4j
currentFormat.setIndent("");
currentFormat.setNewlines(state.isNewlines());
currentFormat.setTrimText(state.isTrimText());
currentFormat.setIndent(state.getIndent());
代码示例来源:origin: stackoverflow.com
OutputFormat format = new OutputFormat(document); //document is an instance of org.w3c.dom.Document
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
String formattedXML = out.toString();
代码示例来源:origin: org.apache.openmeetings/openmeetings-util
public static void toXml(Writer out, Document doc) throws Exception {
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setIndentSize(1);
outformat.setIndent("\t");
outformat.setEncoding(UTF_8.name());
XMLWriter writer = new XMLWriter(out, outformat);
writer.write(doc);
writer.flush();
out.flush();
out.close();
}
代码示例来源:origin: org.mule.modules/mule-module-xml
/**
* @see OutputFormat#setIndent(boolean)
*/
public synchronized void setIndentEnabled(boolean doIndent)
{
outputFormat.setIndent(doIndent);
}
代码示例来源:origin: stackoverflow.com
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
代码示例来源:origin: com.alibaba.citrus/citrus-webx-all
/** 输出DOM。 */
public static void writeDocument(Document doc, Writer writer, String charset) throws IOException {
charset = defaultIfEmpty(trimToNull(charset), "UTF-8");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(charset);
format.setIndent(true);
format.setIndentSize(4);
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(doc);
xmlWriter.flush();
}
代码示例来源:origin: org.mule.modules/mule-module-xml
/**
* @see OutputFormat#setIndent(boolean)
*/
public synchronized void setIndentString(String indentString)
{
outputFormat.setIndent(indentString);
}
代码示例来源:origin: com.intoverflow.booster/booster-core
public static OutputFormat createPrettyPrint() {
// OutputFormat format= OutputFormat.createPrettyPrint();
OutputFormat format = new OutputFormat();
format.setIndentSize(2);
format.setIndent("\t");
format.setNewlines(true);
format.setTrimText(true);
format.setPadText(true);
format.setNewLineAfterDeclaration(false);
return format;
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-io
public static OutputFormat createCompactFormat() {
OutputFormat format = new OutputFormat();
format.setIndent(false);
format.setNewlines(false);
return format;
}
代码示例来源:origin: com.intoverflow.base/intoverflow-util
public static OutputFormat createPrettyPrint() {
// OutputFormat format= OutputFormat.createPrettyPrint();
OutputFormat format = new OutputFormat();
format.setIndentSize(2);
format.setIndent("\t");
format.setNewlines(true);
format.setTrimText(true);
format.setPadText(true);
format.setNewLineAfterDeclaration(false);
return format;
}
内容来源于网络,如有侵权,请联系作者删除!