1

I'm using XStream to generate xml files of my objects. However, the version and encoding header is being omitted from the xml file, and I'm not sure why. Here is my method that prints out the xml file:

public static void personsToXML(ArrayList<Person> persons) throws FileNotFoundException {
        PrintWriter pw = new PrintWriter(new File("someFilePath"));
        XStream xstream = new XStream();
        for (Person i : persons)
            pw.print(xstream.toXML(i));
        pw.close();
    }

It outputs the xml just fine, but there is no header present, as in

<?xml version="1.0"?>

is not present.

Thanks!

zeus_masta_funk
  • 1,388
  • 2
  • 11
  • 34
  • 1
    XStream architecture is based on IO Readers and Writers, while the XML declaration is the responsibility of XML parsers. All HierarchicalStreamDriver implementations respect the encoding since version 1.3, but only if you provide an InputStream. If XStream consumes a Reader you have to initialize the reader with the appropriate encoding yourself, since it is now the reader's task to perform the encoding and no XML parser can change the encoding of a Reader and any encoding definition in the XML header will be ignored. http://xstream.codehaus.org/faq.html – Raghunandan Krishnamurthy Feb 12 '14 at 06:14
  • http://stackoverflow.com/questions/1211624/how-do-i-encode-utf-8-using-the-xstream-framework – Raghunandan Krishnamurthy Feb 12 '14 at 06:17

0 Answers0