org.dom4j.io.OutputFormat.setOmitEncoding()方法的使用及代码示例

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

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

OutputFormat.setOmitEncoding介绍

[英]This will set whether the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) includes the encoding of the document. It is common to suppress this in protocols such as WML and SOAP.
[中]这将设置XML声明(<?xml version="1.0" encoding="UTF-8"?>)是否包含文档的编码。在WML和SOAP等协议中,抑制这种情况很常见。

代码示例

代码示例来源:origin: org.dom4j/dom4j

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: org.mule.modules/mule-module-xml

/**
 * @see OutputFormat#setOmitEncoding(boolean)
 */
public synchronized void setOmitEncoding(boolean omitEncoding)
{
  outputFormat.setOmitEncoding(omitEncoding);
}

代码示例来源:origin: dom4j/dom4j

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: org.jenkins-ci.dom4j/dom4j

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

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

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: apache/servicemix-bundles

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: maven/dom4j

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: org.dom4j/org.motechproject.org.dom4j

setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
  setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
  setIndent(args[++i]);

代码示例来源:origin: dom4j/dom4j

private String rewriteToXmlString(Document doc, boolean trimOn)
    throws IOException {
  org.dom4j.io.OutputFormat of = org.dom4j.io.OutputFormat
      .createCompactFormat();
  of.setIndent(true);
  of.setNewlines(true);
  of.setExpandEmptyElements(false);
  of.setSuppressDeclaration(false);
  of.setOmitEncoding(false);
  of.setEncoding("UTF-8");
  of.setTrimText(trimOn);
  java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
  java.io.BufferedOutputStream bos = new java.io.BufferedOutputStream(os);
  org.dom4j.io.XMLWriter xmlWriter = new org.dom4j.io.XMLWriter(of);
  xmlWriter.setOutputStream(bos);
  xmlWriter.write(doc);
  xmlWriter.close();
  String xml = os.toString();
  // System.out.println("***** xml out *****\n"+xml);
  return xml;
}

代码示例来源:origin: dom4j/dom4j

public void testPadding2() throws Exception {
  Document doc = DocumentFactory.getInstance().createDocument();
  Element root = doc.addElement("root");
  root.addText("prefix");
  root.addElement("b");
  root.addText("suffix");
  OutputFormat format = new OutputFormat("", false);
  format.setOmitEncoding(true);
  format.setSuppressDeclaration(true);
  format.setExpandEmptyElements(true);
  format.setPadText(true);
  format.setTrimText(true);
  StringWriter buffer = new StringWriter();
  XMLWriter writer = new XMLWriter(buffer, format);
  writer.write(doc);
  String xml = buffer.toString();
  System.out.println("xml: " + xml);
  String expected = "<root>prefix<b></b>suffix</root>";
  assertEquals(expected, xml);
}

代码示例来源:origin: dom4j/dom4j

public void testPadding() throws Exception {
  Document doc = DocumentFactory.getInstance().createDocument();
  Element root = doc.addElement("root");
  root.addText("prefix    ");
  root.addElement("b");
  root.addText("      suffix");
  OutputFormat format = new OutputFormat("", false);
  format.setOmitEncoding(true);
  format.setSuppressDeclaration(true);
  format.setExpandEmptyElements(true);
  format.setPadText(true);
  format.setTrimText(true);
  StringWriter buffer = new StringWriter();
  XMLWriter writer = new XMLWriter(buffer, format);
  writer.write(doc);
  String xml = buffer.toString();
  System.out.println("xml: " + xml);
  String expected = "<root>prefix <b></b> suffix</root>";
  assertEquals(expected, xml);
}

相关文章