Namespaces

XJConf is fully namespace aware, that means you can define any tag as often as you want, as long as you use different namespaces:

<defines>
  <namespace uri="http://schst.net/test">
    <tag name="foo" type="java.lang.Integer" keyAttribute="name"/>
  </namespace>
  <namespace uri="http://schst.net/bar">
    <tag name="foo" type="java.lang.String" keyAttribute="name"/>
  </namespace>
</defines>

In this example, the tag foo has been defined twice, once as a java.lang.Integer in the namespace http://schst.net/test and once as a java.lang.String in the namespace http://schst.net/bar as both tag definitions are placed inside the namespace tag.

You may now use both tags in one XML document:

<configuration xmlns:test="http://schst.net/test"
               xmlns:bar="http://schst.net/bar">

  <test:foo name="number">12</test:foo>
  <bar:foo name="text">Now the tag 'foo' is used as a string</bar:foo>
</configuration>

And you can access both values from Java:

import net.schst.XJConf.*;

DefinitionParser tagParser = new DefinitionParser();
NamespaceDefinitions defs = tagParser.parse("xml/defines.xml");

Set namespaces = defs.getDefinedNamespaces();

XmlReader conf = new XmlReader();
conf.setTagDefinitions(defs);

try {
  conf.parse("xml/conf.xml");
} catch (Exception e) {
  e.printStackTrace();
  System.exit(0);
}

Integer number = (Integer)conf.getConfigValue("number");
String text = (String)conf.getConfigValue("text");

If you do not specify a namespace then the namespace URI default will be used to store the tag definitions. This way, it is possible to use XJConf without worrying about namespaces at all.

The XJConf namespace

There's one namespace, that has been reserved for XJConf which uses the URI http://www.schst.net/XJConf as namespace URI. Currently no tags of this namespace have any special meaning, but this may change in the future.

However, you might already want to use this namespace in you XML files:

<xj:configuration xmlns:xj="http://www.schst.net/XJConf">
  <foo>
    Any of your tags will be placed here...
  </foo>
</xj:configuration>