org.jdom2.output.Format.getCompactFormat()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(137)

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

Format.getCompactFormat介绍

[英]Returns a new Format object that performs whitespace normalization, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. Tweaks can be made to the returned Format instance without affecting other instances.
[中]返回一个新的Format对象,该对象执行空白规范化,使用UTF-8编码,不展开空元素,包括声明和编码,并使用默认的实体转义策略。可以对返回的格式实例进行调整,而不会影响其他实例。

代码示例

代码示例来源:origin: usethesource/rascal

public IString xmlCompact(IConstructor node) throws IOException {
  return xmlToString(node, Format.getCompactFormat());
}

代码示例来源:origin: org.apache.jspwiki/jspwiki-main

/**
 *  Serializes the Element to a String. If <tt>pretty</tt> is true,
 *  uses a pretty whitespace format, otherwise a compact format.
 *
 * @param element  the element to serialize.
 * @param pretty   if true, use a pretty whitespace format.
 * @return the serialized Element.
 */
public static String serialize( Element element, boolean pretty ) {
  return serialize( element,pretty ? Format.getPrettyFormat() : Format.getCompactFormat() );
}

代码示例来源:origin: com.theoryinpractise/halbuilder-xml

public void write(ReadableRepresentation representation, Set<URI> flags, Writer writer) {
  final Element element = renderElement("self", representation, false);
  try {
    Format prettyFormat = flags.contains(RepresentationFactory.PRETTY_PRINT)
        ? Format.getPrettyFormat()
        : Format.getCompactFormat();
    final XMLOutputter outputter = new XMLOutputter(prettyFormat);
    outputter.output(element, writer);
  } catch (IOException e) {
    throw new RepresentationException(e);
  }
}

代码示例来源:origin: bioinformatics-ua/dicoogle

XMLOutputter outStream = new XMLOutputter(Format.getCompactFormat());
StringWriter wr = new StringWriter();
try {

代码示例来源:origin: bioinformatics-ua/dicoogle

@Get
  public Representation representXML() {
    StringRepresentation sr;
    
    HashMap<String, Integer> tagList = DictionaryAccess.getInstance().getTagList();
    
    ArrayList<String> list = new ArrayList<String>();
    Element tags = new Element("tags");
    for(String tag : tagList.keySet()){
        int value = tagList.get(tag);
                Element e = new Element("tag");
        e.setAttribute( "id", Integer.toString(value));
        e.setAttribute("name", tag);
        tags.addContent(e);
    } 
    
    tags.setAttribute("count", Integer.toString(tags.getChildren().size()));
    Document xmlDoc = new Document(tags);
    
    XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
    String str = out.outputString(xmlDoc);
    
    StringRepresentation rep = new StringRepresentation( str, MediaType.APPLICATION_XML);
        return rep;
  }
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_pdf

XMLOutputter rawOutputter = new XMLOutputter(Format.getCompactFormat());

代码示例来源:origin: org.opencadc/cadc-test-uws

XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

代码示例来源:origin: org.opencadc/cadc-test-uws

XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

/**
 * Writes to an Writer the XML representation for the given WireFeed.
 * <p>
 * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
 * of the developer to ensure the Writer instance is using the same charset encoding.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
 *        the type given to the FeedOuptut constructor.
 * @param writer Writer to write the XML representation for the given WireFeed.
 * @param prettyPrint pretty-print XML (true) oder collapsed
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
 * @throws IOException thrown if there was some problem writing to the Writer.
 * @throws FeedException thrown if the XML representation for the feed could not be created.
 *
 */
public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
  Document doc = outputJDom(feed);
  String encoding = feed.getEncoding();
  Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  if (encoding!=null) {
    format.setEncoding(encoding);
  }
  XMLOutputter outputter = new XMLOutputter(format);
  outputter.output(doc,writer);
}

代码示例来源:origin: rometools/rome

format = Format.getPrettyFormat();
} else {
  format = Format.getCompactFormat();

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

/**
 * Creates a String with the XML representation for the given WireFeed.
 * <p>
 * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
 * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
 * the feed encoding property.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
 *        the type given to the FeedOuptut constructor.
 * @param prettyPrint pretty-print XML (true) oder collapsed
 * @return a String with the XML representation for the given WireFeed.
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
 * @throws FeedException thrown if the XML representation for the feed could not be created.
 *
 */
public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
  Document doc = outputJDom(feed);
  String encoding = feed.getEncoding();
  Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  if (encoding!=null) {
    format.setEncoding(encoding);
  }
  XMLOutputter outputter = new XMLOutputter(format);
  return outputter.outputString(doc);
}

代码示例来源:origin: apache/marmotta

/**
 * Writes to an Writer the XML representation for the given WireFeed.
 * <p>
 * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
 * of the developer to ensure the Writer instance is using the same charset encoding.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
 *        the type given to the FeedOuptut constructor.
 * @param writer Writer to write the XML representation for the given WireFeed.
 * @param prettyPrint pretty-print XML (true) oder collapsed
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
 * @throws IOException thrown if there was some problem writing to the Writer.
 * @throws FeedException thrown if the XML representation for the feed could not be created.
 *
 */
public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
  Document doc = outputJDom(feed);
  String encoding = feed.getEncoding();
  Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  if (encoding!=null) {
    format.setEncoding(encoding);
  }
  XMLOutputter outputter = new XMLOutputter(format);
  outputter.output(doc,writer);
}

代码示例来源:origin: apache/marmotta

/**
 * Creates a String with the XML representation for the given WireFeed.
 * <p>
 * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
 * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
 * the feed encoding property.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
 *        the type given to the FeedOuptut constructor.
 * @param prettyPrint pretty-print XML (true) oder collapsed
 * @return a String with the XML representation for the given WireFeed.
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
 * @throws FeedException thrown if the XML representation for the feed could not be created.
 *
 */
public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
  Document doc = outputJDom(feed);
  String encoding = feed.getEncoding();
  Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  if (encoding!=null) {
    format.setEncoding(encoding);
  }
  XMLOutputter outputter = new XMLOutputter(format);
  return outputter.outputString(doc);
}

代码示例来源:origin: rometools/rome

format = Format.getPrettyFormat();
} else {
  format = Format.getCompactFormat();

代码示例来源:origin: com.rometools/rome

format = Format.getPrettyFormat();
} else {
  format = Format.getCompactFormat();

代码示例来源:origin: com.rometools/rome

format = Format.getPrettyFormat();
} else {
  format = Format.getCompactFormat();

代码示例来源:origin: pwm-project/pwm

String toXml( )
{
  final Element rootElement = new Element( XML_NODE_ROOT );
  for ( final StoredEvent loopEvent : records )
  {
    if ( loopEvent.getAuditEvent() != null )
    {
      final Element hrElement = new Element( XML_NODE_RECORD );
      hrElement.setAttribute( XML_ATTR_TIMESTAMP, String.valueOf( loopEvent.getTimestamp() ) );
      hrElement.setAttribute( XML_ATTR_TRANSACTION, loopEvent.getAuditEvent().getMessage().getKey() );
      if ( loopEvent.getSourceAddress() != null && loopEvent.getSourceAddress().length() > 0 )
      {
        hrElement.setAttribute( XML_ATTR_SRC_IP, loopEvent.getSourceAddress() );
      }
      if ( loopEvent.getSourceHost() != null && loopEvent.getSourceHost().length() > 0 )
      {
        hrElement.setAttribute( XML_ATTR_SRC_HOST, loopEvent.getSourceHost() );
      }
      if ( loopEvent.getMessage() != null )
      {
        hrElement.setContent( new CDATA( loopEvent.getMessage() ) );
      }
      rootElement.addContent( hrElement );
    }
  }
  final Document doc = new Document( rootElement );
  final XMLOutputter outputter = new XMLOutputter();
  outputter.setFormat( Format.getCompactFormat() );
  return outputter.outputString( doc );
}

相关文章