FlatTree offers adapters to read and write flat files from several XML based APIs:
FlatTree's nodes are mapped to XML nodes, leaves are mapped to XML attributes.
Writing SAX events as a flat file with flattree.xml.sax.FlatHandler :
public ContentHandler createContentHandler(Writer writer) { return new FlatHandler(root, writer); }
Reading a flat file as SAX events with flattree.xml.sax.FlatXMLReader :
public XMLReader createXMLReader() { return new FlatXMLReader(root); }
Writing StAX events as a flat file with flattree.xml.stax.FlatStreamWriter :
public XMLStreamWriter createXMLStreamWriter(Writer writer) { return new FlatStreamWriter(root, writer); }
Reading a flat file as StAX events with flattree.xml.stax.FlatStreamReader
public XMLStreamReader createXMLStreamReader(Reader reader) { return new FlatStreamReader(root, reader); }
Utilizing a flattree.xstream.FlatHierarchicalStreamDriver with XStream. Note how a flattree.xstream.AttributePreferringMapper is used to map simple object fields to XML attributes:
public XStream createXStream() { HierarchicalStreamDriver driver = new FlatHierarchicalStreamDriver(root); return new XStream(driver) { protected MapperWrapper wrapMapper(MapperWrapper next) { return new AttributePreferringMapper(next, getConverterLookup()); } }; }