DocumentStaxUtils.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:gate-core 作者:
/**
 * 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);
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号