A Java object tree implementation based on the Composite Pattern for reading and writing any XML - no need for an XSD.
Each created object can be stored as a node in a tree. There are no special types. Any object can start a fresh tree by being root. A root can store children. Those can be added or set. Any children can be fetched by tag or in case of many with the same name, by listing and filtering. Each object can also store attributes. Those are organized in the same way as child but are used as a list. By any object, the tree can be recursed and generated to any data format. Currently, the generation of XML im implemented only.
The following examples show how to use jPAX.
Children can be added by string for their tag name or by a factory added as object.
IPax root = Instances.Factory().produce("root"); // produce a pax node as named root
root.Child().add("child1"); // add a child node
root.Child().add("child2");
IPax child3 = Instances.Factory().produce("child3");
root.Child().add(child3);Following the code from above, any attribute may be added to any object.
root.Child().get("child2").Attrib().add("is", "active");
IPax child = root.Child().get("child3");
child.Attrib().add("is", "inactive");Any tree node can generate itself. Therefore, one can select the generation.
From code above to be continued.
String xml = root.XML();
System.out.println(xml);Any XML can be parsed to an object tree node, without support of an XSD.
From code above to be continued.
IPax loaded = Reader.Instance.parse("./root.xml");
String xml_ = loaded.XML();
System.out.println(xml_);Alternatively, one can parse a Java InputStream.
String xml; // keeping the xml as string, e.g.
IPax loaded = Reader.Instance.stream(new ByteArrayInputStream(xml.getBytes()));Gradle Wrapper is generated in version 9; try:
./gradlew build jarIf you need to settle another version of the wrapper, get the latest gradle version and install it.
The change to your cloned directory of jPAX and
gradle wrapper
./gradlew build