Since Version 1.4.0 you can expect a null value returned if an element does not exist. The projector will determine the type of the XPath expression and invoke the evaluation accordingly. If you want to avoid null checks, specify java.util.Optional as return type. If you want non existing nodes to be handled like existing empty ones, set the flag ABSENT_IS_EMPTY on projector creation.
Previous answer (up to V1.3.0) Up to version 1.4 it was not possible to distinguish between empty values and non existing values. The cause is a limitation by XPath 1.0, which does not allow all expressions to be evaluated as nodes. Getting a string value from non existing elements or attributes returns an empty string. You will never get a null value from projections returning a string. It is even a common practice to omit empty elements in documents. There are two ways to determine if an element exists:
Now it's easier to upgrade to version 1.4.x.
XPath expressions used in setters (methods with @XBWrite) are limited to absolute paths of non-ambiguous selectors. Functions are not allowed. The reason for this is to make a setter executable regardless of the current document structure, having a reproducible result. If you just need to change values in your DOM tree, use the @XBUpdate annotation on your method. This will allow full XPath syntax.
Example: "/element1/element2/@AttributeName" This works for any setter value that is not a projection nor a collection. The toString() method will be used to create the attribute value.
Example: "/element1/element2" This works for any setter value that is not a projection nor a collection. The toString() method will be used to create the attribute value.
Every projection is associated with a document, every sub projection with a DOM element. To access the DOM Node you may either:
You may change the DOM any time, projections will reflect the changes automatically.
With Java 8, just define a defautl mehtod in your projection interface. For Java 6 & 7 you want to create a mixin:
And register it in your projector:
Caching is not a concern of this library. Implement your own cache to avoid unnecessary XPath overhead. The projector does not know anything about the purpose of the data it reads. To be able to circumvent unexpected caching side effects you need knowledge about the application context.
There are three different ways to change the underlying XPath implementation. You should be able to get everything running that implements the javax.xml.xpath.XPath interface.