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

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

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

OutputFormat.setExpandEmptyElements介绍

[英]This will set whether empty elements are expanded from <tagName> to <tagName></tagName>.
[中]这将设置是否将空元素从<tagName>扩展到<tagName></tagName>

代码示例

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

setIndentSize(Integer.parseInt(args[++i]));
} else if (args[i].startsWith("-expandEmpty")) {
  setExpandEmptyElements(true);
} else if (args[i].equals("-encoding")) {
  setEncoding(args[++i]);

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

format.setTrimText(trim);
format.setXHTML(isXHTML);
format.setExpandEmptyElements(expandEmpty);

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

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

代码示例来源:origin: org.eclipse.hudson.stapler/stapler-jelly

/**
   * False to turn off HTML handling and reenable "/>" for any empty XML element.
   * True to switch back to default mode with HTML handling.
   */
  public void useHTML(boolean enabled) {
    htmlWriter.setEnabled(enabled);
    format.setExpandEmptyElements(enabled);
  }
}

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

/**
   * False to turn off HTML handling and reenable {@code />} for any empty XML element.
   * True to switch back to default mode with HTML handling.
   */
  public void useHTML(boolean enabled) {
    htmlWriter.setEnabled(enabled);
    format.setExpandEmptyElements(enabled);
  }
}

代码示例来源:origin: io.syndesis.server/server-api-generator

public static String serialize(final Document document) {
  try (StringWriter out = new StringWriter()) {
    final OutputFormat format = new OutputFormat(null, false, "UTF-8");
    format.setExpandEmptyElements(false);
    format.setIndent(false);
    final XMLWriter writer = new XMLWriter(out, format);
    writer.write(document);
    writer.flush();
    return out.toString();
  } catch (final IOException e) {
    throw new IllegalStateException("Unable to serialize given document to XML", e);
  }
}

代码示例来源:origin: io.syndesis.rest/rest-connector-generator

public static String serialize(final Document document) {
  try (StringWriter out = new StringWriter()) {
    final OutputFormat format = new OutputFormat(null, false, "UTF-8");
    format.setExpandEmptyElements(false);
    format.setIndent(false);
    final XMLWriter writer = new XMLWriter(out, format);
    writer.write(document);
    writer.flush();
    return out.toString();
  } catch (final IOException e) {
    throw new IllegalStateException("Unable to serialize given document to XML", e);
  }
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

public static String serialize(final Document document) {
  try (StringWriter out = new StringWriter()) {
    final OutputFormat format = new OutputFormat(null, false, "UTF-8");
    format.setExpandEmptyElements(false);
    format.setIndent(false);
    final XMLWriter writer = new XMLWriter(out, format);
    writer.write(document);
    writer.flush();
    return out.toString();
  } catch (final IOException e) {
    throw new IllegalStateException("Unable to serialize given document to XML", e);
  }
}

代码示例来源:origin: com.minlia.iot/minlia-iot

/**
 * 打印XML
 *
 * @param document
 */
protected void printXML(Document document) {
  if (log.isInfoEnabled()) {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setExpandEmptyElements(true);
    format.setSuppressDeclaration(true);
    StringWriter stringWriter = new StringWriter();
    XMLWriter writer = new XMLWriter(stringWriter, format);
    try {
      writer.write(document);
      log.info(stringWriter.toString());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

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

private static OutputFormat createFormat() {
  OutputFormat format = new OutputFormat();
  format.setXHTML(true);
  // Only use short close for tags identified by HTMLWriter:
  format.setExpandEmptyElements(true);
  return format;
}

代码示例来源:origin: org.eclipse.hudson.stapler/stapler-jelly

private static OutputFormat createFormat() {
  OutputFormat format = new OutputFormat();
  format.setXHTML(true);
  // Only use short close for tags identified by HTMLWriter:
  format.setExpandEmptyElements(true);
  return format;
}

代码示例来源:origin: com.googlecode.the-fascinator/fascinator-common

/**
 * Convert node to string
 * 
 * @param outDoc Node to be converted
 * @return String of the converted node
 * @throws IOException if the conversion fail
 */
public String docToString(Node outDoc) throws IOException {
  Writer osw = new StringWriter();
  OutputFormat opf = new OutputFormat("", false, "UTF-8");
  opf.setSuppressDeclaration(true);
  opf.setExpandEmptyElements(true);
  XMLWriter writer = new XMLWriter(osw, opf);
  writer.setEscapeText(false);
  writer.write(outDoc);
  writer.close();
  return osw.toString();
}

代码示例来源:origin: stackoverflow.com

OutputFormat outPutFormat = new OutputFormat();
outPutFormat.setLineSeparator("");
outPutFormat.setExpandEmptyElements(true);
outPutFormat.setEncoding("UTF-8");

Dom4JDriver d4j = new Dom4JDriver(new XmlFriendlyNameCoder("_", "_"));
d4j.setOutputFormat(outPutFormat);
XStream xstream = new XStream(d4j);
xstream.autodetectAnnotations(true);

代码示例来源:origin: com.googlecode.the-fascinator/fascinator-common

/**
   * Convert node to stream
   * 
   * @param outDoc Node to be converted
   * @param outStream output stream of the converted node
   * @throws IOException if the conversion fail
   */
  public void docToStream(Node outDoc, OutputStream outStream)
      throws IOException {
    OutputFormat opf = new OutputFormat("", false, "UTF-8");
    opf.setSuppressDeclaration(true);
    opf.setExpandEmptyElements(true);
    XMLWriter writer = new XMLWriter(outStream, opf);
    writer.setEscapeText(false);
    writer.write(outDoc);
    writer.close();
  }
}

代码示例来源: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

/**
 * This test was provided by Manfred Lotz
 * 
 * @throws Exception
 *             DOCUMENT ME!
 */
public void testWhitespaceBug() throws Exception {
  String notes = "<notes> This is a      multiline\n\rentry</notes>";
  Document doc = DocumentHelper.parseText(notes);
  OutputFormat format = new OutputFormat();
  format.setEncoding("UTF-8");
  format.setIndentSize(4);
  format.setNewlines(true);
  format.setTrimText(true);
  format.setExpandEmptyElements(true);
  StringWriter buffer = new StringWriter();
  XMLWriter writer = new XMLWriter(buffer, format);
  writer.write(doc);
  String xml = buffer.toString();
  log(xml);
  Document doc2 = DocumentHelper.parseText(xml);
  String text = doc2.valueOf("/notes");
  String expected = "This is a multiline entry";
  assertEquals("valueOf() returns the correct text padding", expected,
      text);
  assertEquals("getText() returns the correct text padding", expected,
      doc2.getRootElement().getText());
}

代码示例来源: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);
}

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

format.setNewlines(true);
format.setTrimText(true);
format.setExpandEmptyElements(true);

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

format.setNewlines(true);
format.setTrimText(true);
format.setExpandEmptyElements(true);

相关文章