How to add XML declaration in xml using XMLBeans

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

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

Is there a way to do this natively using XMLBeans? The above can always be concatenated as String for xml content, but this is ugly.

Thanks!

+4
source share
1 answer

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 XML, including encoding information. Save XML declaration with XML, see save (OutputStream) , save (OutputStream, XmlOptions) , save (file) or save (file, XmlOptions) .

+2
source

All Articles