How to add XML declaration to xml with XMLBeans

三世轮回 提交于 2019-12-23 11:59:48

问题


I have this question about Java XMLBeans. I want to include the following declaration at the top of the XML file:

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

Is there anyway to do this natively with XMLBeans? The above can always be concatenated as String to the xml content but that's ugly.

Thanks!


回答1:


The <?xml version="1.0" encoding="UTF-8"?> construct is an XML declaration.

Per 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 save(OutputStream), save(OutputStream, XmlOptions), save(File) or save(File, XmlOptions).



来源:https://stackoverflow.com/questions/16205060/how-to-add-xml-declaration-to-xml-with-xmlbeans

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!