Annotation Type Path

public @interface Path

The Path annotation is used to specify an XML path where an XML element or attribute is located. The format must be in XPath format. When an XML structure does not map exactly to an object model this annotation can be used to navigate the XML document in order to map attributes and elements to an associated field or method. For example, take the annotation shown below.

    private String number;
For the above annotation the XPath expression locates the phone number nested within several elements. Such a declaration can be used when a flat object structure is not suitable. The above annotations will result in the below XML elements.
As can be seen from this XML snippet a single field has been mapped with several elements. These XPath expressions can be used with either elements or attributes to convert an otherwise flat object to XML structure in to something more complex. This is useful when mapping objects to foreign XML formats.

In addition to providing wrappers for existing elements and attributes the Path annotations can be used to provide an ordered set of elements. Order can be applied to the elements created using an XPath index. For example.

    private String home;
    private String office;   
In the above example we have two element annotations within a single class. However each one is given an element path with an index. This tells the serialization process that it should generate two wrapping elements, ordered by the index specified. The above annotations will result in the following.
On deserialization the references to fields are known, and can be read from the order of the wrapping path elements. This is useful if you need to read specific fields or methods from an XML document that maintains elements in sequence. If such sequences contain similarly named child elements, then the ElementList annotation provides a better alternative to indexed XPath expressions.

Niall Gallagher

Required Element Summary
 String value
          This method is used to provide the XPath expression for the annotation.

Element Detail


public abstract String value
This method is used to provide the XPath expression for the annotation. Only a subset of expressions are supported. All path formats can be parsed. However, if the path does not match the supported expressions an exception will be thrown. Some examples of the formats supported are shown below.
There is no limit to the level of nesting supported. Also the Order annotation supports the above formats so that nested elements can be order for serialization of the fields and methods of the annotated types.

this returns an XPath expression for the location