java – 如何使用XMLBeans将XML声明添加到xml

我有关于
Java XMLBeans的这个问题.我想在XML文件的顶部包含以下声明:

<?xml version="1.0" encoding="UTF-8"?>

反正有没有用XMLBeans本地执行此操作?以上内容总是可以作为String连接到xml内容,但这很难看.

谢谢!

最佳答案 <?xml version =“1.0”encoding =“UTF-8”?>构造是一个
XML declaration.

org.apache.xmlbeans.save(ContentHandler ch, LexicalHandler lh)

Writes the XML represented by this source to the given SAX content and
lexical handlers. Note that this method does not save the XML
declaration, including the encoding information. To save the XML
declaration with the XML, see 07002, 07003, 07004 or 07005
.

点赞