本文整理了Java中org.dom4j.io.OutputFormat.<init>()
方法的一些代码示例,展示了OutputFormat.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OutputFormat.<init>()
方法的具体详情如下:
包路径:org.dom4j.io.OutputFormat
类名称:OutputFormat
方法名:<init>
[英]Creates an OutputFormat
with no additional whitespace (indent or new lines) added. The whitespace from the element text content is fully preserved.
[中]创建一个OutputFormat
,不添加额外的空格(缩进或新行)。元素文本内容中的空白被完全保留。
代码示例来源:origin: hibernate/hibernate-orm
private static void dump(Document document) {
if ( !log.isTraceEnabled() ) {
return;
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Writer w = new PrintWriter( baos );
try {
final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) );
xw.write( document );
w.flush();
}
catch (IOException e1) {
throw new RuntimeException( "Error dumping enhanced class", e1 );
}
log.tracef( "Envers-generate entity mapping -----------------------------\n%s", baos.toString() );
log.trace( "------------------------------------------------------------" );
}
}
代码示例来源:origin: hibernate/hibernate-orm
try {
final Writer w = new BufferedWriter( new OutputStreamWriter( baos, "UTF-8" ) );
final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) );
xw.write( document );
w.flush();
代码示例来源: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: hibernate/hibernate-orm
try {
final Writer w = new BufferedWriter( new OutputStreamWriter( baos, "UTF-8" ) );
final XMLWriter xw = new XMLWriter( w, new OutputFormat( " ", true ) );
xw.write( document );
w.flush();
代码示例来源:origin: org.dom4j/dom4j
/**
* Creates a new JAXBModifier for the given JAXB context path. This is the
* Java package where JAXB can find the generated XML classes. This package
* MUST contain jaxb.properties!
*
* @param contextPath
* JAXB context path to be used
*
* @see javax.xml.bind.JAXBContext
*/
public JAXBModifier(String contextPath) {
super(contextPath);
this.outputFormat = new OutputFormat();
}
代码示例来源:origin: org.dom4j/dom4j
/**
* Creates a new JAXBWriter for the given JAXB context path. This is the
* Java package where JAXB can find the generated XML classes. This package
* MUST contain jaxb.properties!
*
* @param contextPath
* JAXB context path to be used
*
* @see javax.xml.bind.JAXBContext
*/
public JAXBWriter(String contextPath) {
super(contextPath);
outputFormat = new OutputFormat();
}
代码示例来源:origin: org.dom4j/dom4j
/**
* Creates a new JAXBModifier for the given JAXB context path, using the
* given {@link java.lang.ClassLoader}. This is the Java package where JAXB
* can find the generated XML classes. This package MUST contain
* jaxb.properties!
*
* @param contextPath
* JAXB context path to be used
* @param classloader
* the classloader to use
*
* @see javax.xml.bind.JAXBContext
*/
public JAXBModifier(String contextPath, ClassLoader classloader) {
super(contextPath, classloader);
this.outputFormat = new OutputFormat();
}
代码示例来源:origin: org.dom4j/dom4j
public void write(Writer out) throws IOException {
XMLWriter writer = new XMLWriter(out, new OutputFormat());
writer.write(this);
}
代码示例来源:origin: org.dom4j/dom4j
public String asXML() {
try {
StringWriter out = new StringWriter();
XMLWriter writer = new XMLWriter(out, new OutputFormat());
writer.write(this);
writer.flush();
return out.toString();
} catch (IOException e) {
throw new RuntimeException("IOException while generating "
+ "textual representation: " + e.getMessage());
}
}
代码示例来源:origin: stackoverflow.com
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
...
XMLSerializer serializer = new XMLSerializer();
serializer.setOutputCharStream(new java.io.FileWriter("output.xml"));
OutputFormat format = new OutputFormat();
format.setStandalone(true);
serializer.setOutputFormat(format);
serializer.serialize(dom);
代码示例来源:origin: org.dom4j/dom4j
public void write(Writer out) throws IOException {
OutputFormat format = new OutputFormat();
format.setEncoding(encoding);
XMLWriter writer = new XMLWriter(out, format);
writer.write(this);
}
代码示例来源:origin: Nepxion/Discovery
public static String getText(Document document, String charset) throws IOException, UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputFormat outputFormat = new OutputFormat(" ", true, charset);
try {
XMLWriter writer = new XMLWriter(baos, outputFormat);
writer.write(document);
baos.flush();
} catch (UnsupportedEncodingException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
if (baos != null) {
baos.close();
}
}
return baos.toString(charset);
}
}
代码示例来源:origin: org.dom4j/dom4j
public String asXML() {
OutputFormat format = new OutputFormat();
format.setEncoding(encoding);
try {
StringWriter out = new StringWriter();
XMLWriter writer = new XMLWriter(out, format);
writer.write(this);
writer.flush();
return out.toString();
} catch (IOException e) {
throw new RuntimeException("IOException while generating textual "
+ "representation: " + e.getMessage());
}
}
代码示例来源:origin: webx/citrus
private static void writeDocument(Document doc, OutputStream stream) throws IOException {
String charset = "UTF-8";
Writer writer = new OutputStreamWriter(stream, charset);
OutputFormat format = new OutputFormat();
format.setEncoding(charset);
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(doc);
xmlWriter.flush();
}
代码示例来源:origin: webx/citrus
private static void writeDocument(Document doc, OutputStream stream) throws IOException {
String charset = "UTF-8";
Writer writer = new OutputStreamWriter(stream, charset);
OutputFormat format = new OutputFormat();
format.setEncoding(charset);
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(doc);
xmlWriter.flush();
}
代码示例来源:origin: webx/citrus
private static void writeDocument(Document doc, OutputStream stream) throws IOException {
String charset = "UTF-8";
Writer writer = new OutputStreamWriter(stream, charset);
OutputFormat format = new OutputFormat();
format.setEncoding(charset);
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 of = new OutputFormat();
代码示例来源: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: org.dom4j/dom4j
/**
* A static helper method to create the default pretty printing format. This
* format consists of an indent of 2 spaces, newlines after each element and
* all other whitespace trimmed, and XMTML is false.
*
* @return DOCUMENT ME!
*/
public static OutputFormat createPrettyPrint() {
OutputFormat format = new OutputFormat();
format.setIndentSize(2);
format.setNewlines(true);
format.setTrimText(true);
format.setPadText(true);
return format;
}
内容来源于网络,如有侵权,请联系作者删除!