How to create the tag <?xml version="1.0" encoding="ISO-8859-1"?> with XMLOption (XMLBeans)?

2.8k views Asked by At

How can i create the header of a XML Document, which was created by using XML Beans and XMLOptions?

I have developed this kind of java code to the right encoding and deleted unnecessary namespaces:

final Map<String, String> implicitNamespaces = new HashMap<String, String>();
implicitNamespaces.put("", "http://www.test.com/results");
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSaveImplicitNamespaces(implicitNamespaces);
xmlOptions.setCharacterEncoding("ISO-8859-1");
xmlOptions.setSavePrettyPrint();

But how can i create the header by using XMLBeans and XMLOptions? Is it the only way to set it hard coded? If there is´t a method to create this tag?

1

There are 1 answers

0
kjhughes On

The <?xml version=“1.0” encoding=“ISO-8859-1”?> 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).