/**
* Returns a string containing the specified document in GATE XML
* format.
*
* @param doc the document
*/
public static String toXml(Document doc) {
try {
if(outputFactory == null) {
outputFactory = XMLOutputFactory.newInstance();
}
StringWriter sw = new StringWriter(doc.getContent().size().intValue()
* DocumentXmlUtils.DOC_SIZE_MULTIPLICATION_FACTOR);
XMLStreamWriter xsw = outputFactory.createXMLStreamWriter(sw);
// start the document
if(doc instanceof TextualDocument) {
xsw.writeStartDocument(((TextualDocument)doc).getEncoding(), "1.0");
}
else {
xsw.writeStartDocument("1.0");
}
newLine(xsw);
writeDocument(doc, xsw, "");
xsw.close();
return sw.toString();
}
catch(XMLStreamException xse) {
throw new GateRuntimeException("Error converting document to XML", xse);
}
}
DocumentStaxUtils.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:gate-core
作者:
评论列表
文章目录