DataNucleus supports persisting/retrieving objects to/from XML documents (using the datanucleus-xml plugin). Simply specify your "connectionURL" as follows
datanucleus.ConnectionURL=xml:file:myfile.xml
replacing myfile.xml with your filename, which can be absolute or relative.
It makes use of JAXB, and the jars required to use DataNucleus XML persistence are datanucleus-core, datanucleus-api-jdo/datanucleus-api-jpa, datanucleus-xml and JAXB API, JAXB Reference Implementation. If you wish to help out in this effort either by contributing or by sponsoring particular functionality please contact us via the DataNucleus Forum.
Things to bear in mind with XML usage :-
When persisting a Java object to an XML datastore clearly the user would like some control over the structure of the XML document. Here's an example using JDO XML MetaData
<jdo> <package name="org.datanucleus.samples.models.company"> <class name="Person" detachable="true" schema="/myproduct/people" table="person"> <field name="personNum"> <extension vendor-name="datanucleus" key="XmlAttribute" value="true"/> </field> <field name="firstName" primary-key="true"/> <!-- PK since JAXB requires String --> <field name="lastName"/> <field name="bestFriend"/> </class> </package> </jdo>
Things to note :
What is generated with the above is as follows
<?xml version="1.0" encoding="UTF-8"?> <myproduct> <people> <person personNum="1"> <firstName>Bugs</firstName> <lastName>Bunny</lastName> <bestFriend>My</bestFriend> </person> </people> </myproduct>
Here's the same example using JDO Annotations
@PersistenceCapable(schema="/myproduct/people", table="person") public class Person { @XmlAttribute private long personNum; @PrimaryKey private String firstName; private String lastName; private Person bestFiend; @XmlElementWrapper(name="phone-numbers") @XmlElement(name="phone-number") @Element(types=String.class) private Map phoneNumbers = new HashMap(); ...
Here's the same example using JPA Annotations (with DataNucleus @Extension/@Extensions annotations)
TODO Add this example