本文整理了Java中org.apache.xml.serialize.OutputFormat
类的一些代码示例,展示了OutputFormat
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OutputFormat
类的具体详情如下:
包路径:org.apache.xml.serialize.OutputFormat
类名称:OutputFormat
[英]Specifies an output format to control the serializer. Based on the XSLT specification for output format, plus additional parameters. Used to select the suitable serializer and determine how the document should be formatted on output.
The two interesting constructors are:
代码示例来源:origin: jersey/jersey
private static XMLSerializer getXMLSerializer(final OutputStream os, final String[] cdataElements)
throws InstantiationException,
IllegalAccessException, ClassNotFoundException {
// configure an OutputFormat to handle CDATA
final OutputFormat of = new OutputFormat();
// specify which of your elements you want to be handled as CDATA.
// The use of the '^' between the namespaceURI and the localname
// seems to be an implementation detail of the xerces code.
// When processing xml that doesn't use namespaces, simply omit the
// namespace prefix as shown in the third CDataElement below.
of.setCDataElements(cdataElements);
// set any other options you'd like
of.setPreserveSpace(true);
of.setIndenting(true);
// create the serializer
final XMLSerializer serializer = new XMLSerializer(of);
serializer.setOutputByteStream(os);
return serializer;
}
代码示例来源:origin: graphhopper/jsprit
private OutputFormat createOutputFormat() {
OutputFormat format = new OutputFormat();
format.setIndenting(true);
format.setIndent(5);
return format;
}
代码示例来源:origin: pentaho/mondrian
OutputFormat format;
if (doc != null) {
format = new OutputFormat(doc, null, prettyPrint);
} else {
format = new OutputFormat("xml", null, prettyPrint);
format.setLineWidth(0); // don't wrap lines
format.setLineSeparator(LINE_SEP);
} else {
format.setLineSeparator("");
XMLSerializer serial = new XMLSerializer(writer, format);
serial.asDOMSerializer();
if (node instanceof Document) {
serial.serialize((Document) node);
} else if (node instanceof Element) {
format.setOmitXMLDeclaration(true);
serial.serialize((Element) node);
} else if (node instanceof DocumentFragment) {
format.setOmitXMLDeclaration(true);
serial.serialize((DocumentFragment) node);
} else if (node instanceof Text) {
代码示例来源:origin: stackoverflow.com
OutputFormat format = new OutputFormat(document);
format.setIndenting(true);
format.setOmitXMLDeclaration(true);
代码示例来源:origin: org.wso2.bpel/ode-utils
/**
* @deprecated relies on XMLSerializer which is a deprecated Xerces class, use domToString instead
*/
static public String prettyPrint(Element e) throws IOException {
OutputFormat format = new OutputFormat(e.getOwnerDocument());
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
StringWriter out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(e);
return out.toString();
}
代码示例来源:origin: Quetzal-RDF/quetzal
default void printDocument(Document doc) throws Exception {
OutputFormat format = new OutputFormat(doc);
format.setIndenting(true);
XMLSerializer serializer = new XMLSerializer(System.out, format);
serializer.serialize(doc);
}
代码示例来源:origin: org.fcrepo/fcrepo-common
private static OutputFormat getConsoleWithDocType() {
OutputFormat fmt = new OutputFormat("XML", "UTF-8", true);
fmt.setIndent(2);
fmt.setLineWidth(80);
fmt.setPreserveSpace(false);
// default is false
fmt.setOmitXMLDeclaration(false);
// default is false
fmt.setOmitDocumentType(false);
return fmt;
}
代码示例来源:origin: org.opengis.cite/cite1-utils
public static void writeXml(Element element, Writer out, int indent)
throws IOException
{
OutputFormat format = new OutputFormat("XML", "UTF-8", false);
format.setOmitComments(false);
if (indent > 0) {
format.setIndenting(true);
format.setIndent(indent);
}
format.setLineWidth(0);
XMLSerializer serializer = new XMLSerializer(format);
serializer.setOutputCharStream(out);
serializer.serialize(element);
}
代码示例来源:origin: fcrepo3/fcrepo
private static OutputFormat getPrettyPrint() {
OutputFormat fmt = new OutputFormat("XML", "UTF-8", true);
fmt.setEncoding("UTF-8");
fmt.setIndenting(true);
fmt.setIndent(2);
fmt.setOmitXMLDeclaration(true);
return fmt;
}
代码示例来源:origin: org.eclipse/org.eclipse.wst.wsi
/**
* Serializes document.
*
* @param doc an org.w3c.dom.Document object.
* @param writer a java.io.Writer object.
* @throws Exception if unable to serialize the document.
*/
public static void serializeDoc(Document doc, Writer writer)
throws java.lang.Exception {
XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml",
"UTF-8", true));
s.serialize(doc);
}
代码示例来源:origin: org.kuali.maven.impex/torque-generator
/**
* This is the XMLSerializer responsible for outputting the XML document
*/
protected XMLSerializer getSerializer(final Writer out) {
return new XMLSerializer(out, new OutputFormat(Method.XML, getEncoding(), true));
}
代码示例来源:origin: org.opengis.cite/cite1-utils
public static void writeXml(Element element, OutputStream os)
throws IOException
{
OutputFormat format = new OutputFormat("XML", "UTF-8", false);
format.setOmitComments(false);
format.setLineWidth(0);
XMLSerializer serializer = new XMLSerializer(format);
serializer.setOutputByteStream(os);
serializer.serialize(element);
}
代码示例来源:origin: pentaho/mondrian
public static void validate(
Document doc,
String schemaLocationPropertyValue,
EntityResolver resolver)
throws IOException,
SAXException
{
OutputFormat format = new OutputFormat(doc, null, true);
StringWriter writer = new StringWriter(1000);
XMLSerializer serial = new XMLSerializer(writer, format);
serial.asDOMSerializer();
serial.serialize(doc);
String docString = writer.toString();
validate(docString, schemaLocationPropertyValue, resolver);
}
代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs
/**
* Create a processor that writes to the file named and may or may not
* also output to the screen, as specified.
*
* @param filename Name of file to write output to
* @param printToScreen Mirror output to screen?
*/
public XmlEditsVisitor(OutputStream out)
throws IOException {
this.out = out;
OutputFormat outFormat = new OutputFormat("XML", "UTF-8", true);
outFormat.setIndenting(true);
outFormat.setIndent(2);
outFormat.setDoctype(null, null);
XMLSerializer serializer = new XMLSerializer(out, outFormat);
contentHandler = serializer.asContentHandler();
try {
contentHandler.startDocument();
contentHandler.startElement("", "", "EDITS", new AttributesImpl());
} catch (SAXException e) {
throw new IOException("SAX error: " + e.getMessage());
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-insync
/** Generate the html string from the given element */
public static String getHtmlStream(Element element) {
StringWriter w = new StringWriter(); // XXX initial size?
OutputFormat format = new OutputFormat(element.getOwnerDocument(), null, true); // default enc, do-indent
format.setLineWidth(160);
format.setIndent(4);
JspxSerializer serializer = new JspxSerializer(w, format);
try {
serializer.serialize(element);
} catch (java.io.IOException ex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
}
return w.getBuffer().toString();
}
代码示例来源:origin: net.oneandone.cosmo/cosmo-core
public static String serialize(XmlSerializable serializable)
throws IOException {
StringWriter out = new StringWriter();
try {
Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument();
doc.appendChild(serializable.toXml(doc));
OutputFormat format = new OutputFormat("xml", "UTF-8", true);
XMLSerializer serializer =
new XMLSerializer(out, format);
serializer.setNamespaces(true);
serializer.asDOMSerializer().serialize(doc);
return out.toString();
} catch (ParserConfigurationException e) {
throw new CosmoParseException(e);
}
}
}
代码示例来源:origin: org.owasp/antisamy
OutputFormat format = new OutputFormat();
format.setEncoding(outputEncoding);
format.setEncoding(outputEncoding);
format.setOmitXMLDeclaration( "true".equals(policy.getDirective(Policy.OMIT_XML_DECLARATION)) );
format.setOmitDocumentType( "true".equals(policy.getDirective(Policy.OMIT_DOCTYPE_DECLARATION)) );
format.setPreserveEmptyAttributes(true);
format.setLineWidth(80);
format.setIndenting(true);
format.setIndent(2);
format.setPreserveSpace( preserveSpace );
代码示例来源:origin: com.ibm.sbt/com.ibm.commons.xml
private XMLSerializer createXMLSerializer(Node node, Format fmt) {
if(fmt==null) {
fmt = Format.defaultFormat;
}
OutputFormat format = new OutputFormat(); //node.getOwnerDocument());
format.setIndent(fmt.indent);
format.setOmitXMLDeclaration(!fmt.xmlDecl);
format.setEncoding(fmt.encoding);
return new XMLSerializer(format);
}
代码示例来源:origin: org.jasig.portal/uportal3-impl
public SerializingUserLayoutDao() {
layoutOutputFormat=new OutputFormat();
layoutOutputFormat.setIndenting(true);
layoutOutputFormat.setLineWidth(0);
layoutOutputFormat.setOmitDocumentType(false);
layoutOutputFormat.setPreserveSpace(true);
layoutOutputFormat.setEncoding("UTF-8");
layoutOutputFormat.setOmitComments(false);
layoutOutputFormat.setOmitXMLDeclaration(false);
layoutOutputFormat.setDoctype(publicDoctype, systemDoctype);
}
代码示例来源:origin: org.nuxeo.common/nuxeo-common
public static String toStringOmitXml(Element element) throws IOException {
OutputFormat of = new OutputFormat();
of.setOmitXMLDeclaration(true);
return toString(element, of);
}
内容来源于网络,如有侵权,请联系作者删除!