Fork me on GitHub

XML support

Since JDK 1.5 Java properties support XML format via loadFromXML() and storeToXML()

There is no reason why OWNER API shouldn't implement XML support as the Properties class.

But OWNER goes beyond that.

The Java XML Properties format

The java.util.Properties class supports an XML format that looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "">
    <comment>this is an example</comment>
    <entry key="server.ssh.alive.interval">60</entry>
    <entry key="server.ssh.address"></entry>
    <entry key="server.http.port">80</entry>
    <entry key="server.http.hostname">localhost</entry>
    <entry key="server.ssh.user">admin</entry>
    <entry key="server.ssh.port">22</entry>

Don't you agree that the above example is quite an unstructured XML format?

OWNER is able to load this XML as configuration properties, but it is also possible to specify an XML more structured, that can be defined from the user on his own taste.

The user's specified XML format

If you don't like the Java XML Properties format, then you can define an XML of your own:

    <http port="80">
    <ssh port="22">
        <alive interval="60"/>

For OWNER, the above example is equivalent to the example listed in the previous section (the Java XML Properties format)

XML elements, and XML attributes will be converted to properties names, and attribute values and element values will be converted to properties values.

This means that the above xml would be equivalent to a properties file like the following:


Loading the XML

How to load the XML into OWNER Config object? Simple: in the same way as you already do for properties file.

Suppose you have a mapping interface class in a source file called, just place a resource in your classpath in Or you can specify the @Sources annotation with an URL pointing to an file.xml. OWNER will notice the .xml extension and will load the configuration source as XML.

The mapping interface for the two above XML examples is the following:

interface ServerConfig extends Config {

    int httpPort();

    String httpHostname();

    int sshPort();

    String sshAddress();

    int aliveInterval();

    String sshUser();

Storing to XML

If you are looking for the method to store a Config object into an XML stream, you should have a look at the method storeToXML in the Accessible interface.

When saving a Config object to XML, the Java XML Properties format will be used.


If you like XML format more than properties format (well, I don't), you can use XML to achieve the same result as using properties files.