当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamWriter.setDefaultNamespace方法代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamWriter.setDefaultNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamWriter.setDefaultNamespace方法的具体用法?Java XMLStreamWriter.setDefaultNamespace怎么用?Java XMLStreamWriter.setDefaultNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.stream.XMLStreamWriter的用法示例。


在下文中一共展示了XMLStreamWriter.setDefaultNamespace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeXcesAnnotations

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * Save annotations to the given XMLStreamWriter in XCES format. The
 * writer is <i>not</i> closed by this method, that is left to the
 * caller. This method writes just the cesAna element - the XML
 * declaration must be filled in by the caller if required. Characters
 * in feature values that are illegal in XML are replaced by
 * {@link #INVALID_CHARACTER_REPLACEMENT} (a space). Feature <i>names</i>
 * are not modified, nor are annotation types - an illegal character
 * in one of these will cause the serialization to fail.
 * 
 * @param annotations the annotations to save, typically an
 *          AnnotationSet
 * @param xsw the XMLStreamWriter to write to
 * @param includeId should we include the annotation IDs (as the "n"
 *          attribute on each <code>struct</code>)?
 * @throws XMLStreamException
 */
public static void writeXcesAnnotations(Collection<Annotation> annotations,
        XMLStreamWriter xsw, boolean includeId) throws XMLStreamException {
  List<Annotation> annotsToDump = new ArrayList<Annotation>(annotations);
  Collections.sort(annotsToDump, LONGEST_FIRST_OFFSET_COMPARATOR);

  xsw.setDefaultNamespace(XCES_NAMESPACE);
  xsw.writeStartElement(XCES_NAMESPACE, "cesAna");
  xsw.writeDefaultNamespace(XCES_NAMESPACE);
  xsw.writeAttribute("version", XCES_VERSION);
  newLine(xsw);

  String indent = "   ";
  String indentMore = indent + indent;

  for(Annotation a : annotsToDump) {
    long start = a.getStartNode().getOffset().longValue();
    long end = a.getEndNode().getOffset().longValue();
    FeatureMap fm = a.getFeatures();
    xsw.writeCharacters(indent);
    if(fm == null || fm.size() == 0) {
      xsw.writeEmptyElement(XCES_NAMESPACE, "struct");
    }
    else {
      xsw.writeStartElement(XCES_NAMESPACE, "struct");
    }
    xsw.writeAttribute("type", a.getType());
    xsw.writeAttribute("from", String.valueOf(start));
    xsw.writeAttribute("to", String.valueOf(end));
    // include the annotation ID as the "n" attribute if requested
    if(includeId) {
      xsw.writeAttribute("n", String.valueOf(a.getId()));
    }
    newLine(xsw);

    if(fm != null && fm.size() != 0) {
      for(Map.Entry<Object,Object> att : fm.entrySet()) {
        if(!"isEmptyAndSpan".equals(att.getKey())) {
          xsw.writeCharacters(indentMore);
          xsw.writeEmptyElement(XCES_NAMESPACE, "feat");
          xsw.writeAttribute("name", String.valueOf(att.getKey()));
          xsw.writeAttribute("value",
                  replaceXMLIllegalCharactersInString(String.valueOf(att
                          .getValue())));
          newLine(xsw);
        }
      }
      xsw.writeCharacters(indent);
      xsw.writeEndElement();
      newLine(xsw);
    }
  }

  xsw.writeEndElement();
  newLine(xsw);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:73,代码来源:DocumentStaxUtils.java


注:本文中的javax.xml.stream.XMLStreamWriter.setDefaultNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。