org.apache.xml.serialize.OutputFormat.setEncoding()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.apache.xml.serialize.OutputFormat.setEncoding()方法的一些代码示例,展示了OutputFormat.setEncoding()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OutputFormat.setEncoding()方法的具体详情如下:
包路径:org.apache.xml.serialize.OutputFormat
类名称:OutputFormat
方法名:setEncoding

OutputFormat.setEncoding介绍

[英]Sets the encoding for this output method. If no encoding was specified, the default is always "UTF-8". Make sure the encoding is compatible with the one used by the java.io.Writer.
[中]设置此输出方法的编码。如果未指定编码,则默认值始终为“UTF-8”。确保编码与java使用的编码兼容。伊奥。作家

代码示例

代码示例来源:origin: org.geotools/gt2-xml-xsd

/**
 * Sets the charset encoding scheme to be used in encoding XML content.
 * <p>
 * This encoding will determine the resulting character encoding for the XML
 * content generated by this Encoder and will be reflected in the XML
 * declaration tag.
 * </p>
 * 
 * @param charset
 *            the (non null) charset to encode XML content accordingly to
 */
public void setEncoding(final Charset charset) {
  final String charsetName = charset.name();
  outputFormat.setEncoding(charsetName);
}

代码示例来源:origin: org.geotools.xsd/gt-core

/**
 * Sets the charset encoding scheme to be used in encoding XML content.
 * <p>
 * This encoding will determine the resulting character encoding for the XML
 * content generated by this Encoder and will be reflected in the XML
 * declaration tag.
 * </p>
 * 
 * @param charset
 *            the (non null) charset to encode XML content accordingly to
 */
public void setEncoding(final Charset charset) {
  final String charsetName = charset.name();
  outputFormat.setEncoding(charsetName);
}

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

/**
 * Constructs a new output format with the proper method,
 * document type identifiers and media type for the specified
 * document, and with the specified encoding. If <tt>indent</tt>
 * is true, the document will be pretty printed with the default
 * indentation level and default line wrapping.
 *
 * @param doc The document to output
 * @param encoding The specified encoding
 * @param indenting True for pretty printing
 * @see #setEncoding
 * @see #setIndenting
 * @see #whichMethod
 */
public OutputFormat( Document doc, String encoding, boolean indenting )
{
  this( doc );
  setEncoding( encoding );
  setIndenting( indenting );
}

代码示例来源:origin: org.onehippo.cms7/hippo-cms-plugins

private String prettyPrint(byte[] bytes) throws Exception {
    Source source = new StreamSource(new ByteArrayInputStream(bytes));
    DOMResult result = new DOMResult();
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer identityTransformer = transformerFactory.newTransformer();
    identityTransformer.transform(source, result);
    Document doc = (Document) result.getNode();

    OutputFormat format = new OutputFormat(doc);
    format.setEncoding("UTF-8");
    format.setIndenting(true);
    format.setIndent(2);
    format.setLineWidth(80);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLSerializer xmlSerializer = new XMLSerializer(out, format);
    xmlSerializer.serialize(doc);
    return out.toString("UTF-8");
  }
}

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

/**
 * Constructs a new output format with the default values for
 * the specified method and encoding. If <tt>indent</tt>
 * is true, the document will be pretty printed with the default
 * indentation level and default line wrapping.
 *
 * @param method The specified output method
 * @param encoding The specified encoding
 * @param indenting True for pretty printing
 * @see #setEncoding
 * @see #setIndenting
 * @see #setMethod
 */
public OutputFormat( String method, String encoding, boolean indenting )
{
  setMethod( method );
  setEncoding( encoding );
  setIndenting( indenting );
}

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

private void copySettings(XMLSerializer src, XMLSerializer dest) {
  dest.fDOMErrorHandler = fErrorHandler;
  dest._format.setEncoding(src._format.getEncoding());
  dest._format.setLineSeparator(src._format.getLineSeparator());
  dest.fDOMFilter = src.fDOMFilter;
}//copysettings

代码示例来源:origin: org.fcrepo/fcrepo-common

private static OutputFormat getPrettyPrintWithDecl() {
    OutputFormat fmt = new OutputFormat("XML", "UTF-8", true);
    fmt.setEncoding("UTF-8");
    fmt.setIndenting(true);
    fmt.setIndent(2);
    fmt.setOmitXMLDeclaration(false);
    return fmt;
  }
}

代码示例来源: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.fcrepo/fcrepo-common

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: 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: fcrepo3/fcrepo

private static OutputFormat getPrettyPrintWithDecl() {
    OutputFormat fmt = new OutputFormat("XML", "UTF-8", true);
    fmt.setEncoding("UTF-8");
    fmt.setIndenting(true);
    fmt.setIndent(2);
    fmt.setOmitXMLDeclaration(false);
    return fmt;
  }
}

代码示例来源:origin: org.openxri/com.springsource.org.openxri.resolve

/**
 * Converts a <code>Document</code> into a formated XML string.
 * @param doc <code>Document</code> to be converted into a string.
 * @return a string representing the formated XML document
 */
public static String toString( Document doc )
{
    StringWriter str = new StringWriter();
    try
    {
      OutputFormat out = new OutputFormat(doc);
      out.setIndenting(true);
      out.setIndent(1);
      out.setStandalone(false);
      out.setEncoding("UTF-8");
      out.setLineWidth(0);
      XMLSerializer ser = new XMLSerializer(str, out);
      ser.serialize(doc.getDocumentElement());  
    }
    catch( Exception e )
    {
      return null;
    }
    return str.toString();
}

代码示例来源:origin: org.apache.kalumet/org.apache.kalumet.common

/**
 * Writes the Kalumet agent XML log file using in-memory DOM.
 */
public synchronized void writeXMLFile()
{
 try
 {
  OutputFormat format = new OutputFormat();
  format.setLineWidth( 72 );
  format.setIndenting( true );
  format.setIndent( 3 );
  format.setEncoding( "ISO-8859-1" );
  XMLSerializer serializer =
   new XMLSerializer( new FileOutputStream( this.basedir + "/" + MAIN_LOG_FILE ), format );
  serializer.serialize( this.toDOMElement( new CoreDocumentImpl( true ) ) );
 }
 catch ( Exception e )
 {
  LOG.error( "Can't write update log file.", e );
 }
}

代码示例来源:origin: org.openxri/openxri-client

/**
 * Converts a <code>Document</code> into a formated XML string.
 * @param doc <code>Document</code> to be converted into a string.
 * @return a string representing the formated XML document
 */
public static String toString( Document doc )
{
    StringWriter str = new StringWriter();
    try
    {
      OutputFormat out = new OutputFormat(doc);
      out.setIndenting(true);
      out.setIndent(1);
      out.setStandalone(false);
      out.setEncoding("UTF-8");
      out.setLineWidth(0);
      XMLSerializer ser = new XMLSerializer(str, out);
      
      // normalizeDocument adds "xmlns" attributes, among other normalization
      doc.normalizeDocument(); // XXX: should we clone the document?
      ser.serialize(doc.getDocumentElement());  
    }
    catch( Exception e )
    {
      return null;
    }
    return str.toString();
}

代码示例来源:origin: org.apache.kalumet/org.apache.kalumet.common

format.setIndenting( true );
format.setIndent( 3 );
format.setEncoding( "ISO-8859-1" );
if ( path.startsWith( "http:" ) || path.startsWith( "http:" ) )

代码示例来源:origin: org.apache.kalumet/org.apache.kalumet.common

format.setIndenting( true );
format.setIndent( 3 );
format.setEncoding( "ISO-8859-1" );
if ( path.startsWith( "http:" ) || path.startsWith( "http:" ) )

代码示例来源:origin: org.owasp/antisamy

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)) );

代码示例来源: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: com.rackspace.apache/xerces2-xsd11

try {
  prepareForSerialization(ser, wnode);
  ser._format.setEncoding("UTF-16");
  ser.setOutputCharStream(destination);
  if (wnode.getNodeType() == Node.DOCUMENT_NODE) {

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

ser._format.setEncoding(encoding);
ser.setOutputByteStream(XMLEntityManager.createOutputStream(URI));

相关文章