Skip to content
/ jPAX Public

A pretty simple Java Data Passenger - building object trees that can write and may read from XML

License

Notifications You must be signed in to change notification settings

graetz23/jPAX

Repository files navigation

jPAX

A Java object tree implementation based on the Composite Pattern for reading and writing any XML - no need for an XSD.

Introduction

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.

HowTo

The following examples show how to use jPAX.

Creating a root and adding Children

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);

Creating Attributes

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");

Generating XML and writting it

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);

Parsing XML to object Tree Node

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()));

Build

Gradle Wrapper is generated in version 9; try:

./gradlew build jar

If 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

About

A pretty simple Java Data Passenger - building object trees that can write and may read from XML

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages