Skip navigation links

Package org.opencypher.tools.xml

This package contains utilities that read XML files and build up a custom object graph by mapping the XML structure to annotated classes.

See: Description

Package org.opencypher.tools.xml Description

This package contains utilities that read XML files and build up a custom object graph by mapping the XML structure to annotated classes.

In order to parse XML into you object graph, you need to create an XmlParser for your root object type:

XmlParser<MyRoot> PARSER = XmlParser.xmlParser( MyRoot.class );
Your class MyRoot and the child node types should be annotated with @Element and have fields annotated with @Attribute to map the attributes of the xml element, and methods annotated with @Child to map the child elements of the xml element.

Accepted types for fields annotated with @Attribute are:

(See the source code of AttributeHandler for details)

It is also possible to use the @Attribute annotation on a method that accepts a single argument (and returns void). The accepted argument types are the same as for fields annotated with @Attribute.

Methods annotated with @Child may have any name, should return void and have one of the following parameters lists:

Once a parser has been created, parsing an XML file to generate an object graph is as simple as invoking one of the parse-methods: There are also some more advanced features of the XML-to-object mapping available, such as: In terms of implementation, mapping the object class structure into a parser that can be used to parse an XML file is handled by Structure. This class is responsible for creating NodeBuilder objects that knows how to instantiate and build objects for the various XML entities that the parser encounters. The actual parsing, and keeping track of which NodeBuilder maps to what part of the XML file is handled by ParserStateMachine. Converting XML attributes into values that can be assigned to fields, or passed into methods annotated with @Attribute is handled by AttributeHandler, which also handles the actual field assignment or invocation. For creating XmlFile attribute values, a Resolver instance is used for finding the xml file in question.
Skip navigation links

Copyright © 2019. All rights reserved.