I want to configure xjc to annotate a certain attribute in a generated Java class using the jaxb2-basics-annotate plugin but I am struggling to address the particular XML element with XPath.
Here is an extract of the xsd (which btw, cannot be changed by myself):
<xs:complexType name="ExpressionType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
The corresponding xjc-generated Java class looks like this:
....
public class ExpressionType
{
@XmlValue
protected String value;
@XmlAttribute(name = "id", required = true)
protected String id;
...
in the bindings.xjb
file I'd like to configure that the Java attribute value
gets annotated by annotation XmlJavaTypeAdapter
, so something like this:
<jxb:bindings node="//xs:complexType[@name='ExpressionType']/<???>" multiple="true">
<annox:annotate target="field">@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(MyOwnCdataAdapter.class)</annox:annotate>
</jxb:bindings>
The three ???
refer to my question ;-) : How to address the inner content which is mapped to Java attribute value
in XPath?
For the id
attribute I succeeded using
//xs:complexType[@name='ExpressionType']/xs:simpleContent/xs:extension/xs:attribute[@name='id']
but for my demands, I don't see how to express this in xpath, also reflecting that the type is an extension of xs:string
.