问题
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