本文整理匯總了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);
}