// Serialize the Person object into a file.
// Omit all xsi:type, xsi:nil and id attributes.
// This will shorten the output and make it more "human readable",
// but this may not work correctly for all kinds of objects.
out = new FileOutputStream("fred_short.xml");
trans.serialize(fred, new StreamResult(out));
out.close();
// ... and deserialize it again
// Note that the transformer used for deserialization also needs
// the property OMIT_XSI_TYPE
in = new FileInputStream("fred_short.xml");