MOXy @XmlPath expressions, are they supported?

518 views Asked by At

Are XPath expressions such as the following supported in MOXy?

field[XMLtag!='identifier']

Basically I've got XML like this

<demographics>
  <field>
    <value>12345</value>
    <XMLtag>identifier</XMLtag>
  </field>
  <field>
    <value>somename</value>
    <XMLtag>name</XMLtag>
  </field>
</demographics>

I'm trying to get a List to populate with but exclude the field which is for identifier.

This will work but gives me all field elements (2) in the List ( correctly )

@XmlElement( name = "field" )
public List<Field2> fieldList;

This will not, I get an empty List

@XmlPath( "field[XMLtag!='identifier']" )
public List<Field2> fieldList;

Should the above work, or are expressions like that not supported by MOXy? I can't seem to find any information about them.

I've not included my Field2 class as it's very simple and obviously works okay as I can unmarshall to list if using @XmlElement annotation. Let me know if you'd like to see it.

1

There are 1 answers

0
bdoughan On

EclipseLink JAXB (MOXy)'s @XmlPath annotation supports a subset of the XPath specification. The XPath handling is done by MOXy itself. The following concepts are supported:

  • Attribute - @id
  • Element - address
  • Element by Position - address[1]
  • Element by Predicate - address[@type='mailing']
  • Element Text - name/text()
  • Text - text()
  • Self - .
  • Combination - personal-info/name[2]/text()

For namespace qualified nodes, the prefixes defined in the @XmlNs annotations can be used to qualify the XPath fragments. Unqualified fragments will assumed to be in the namespace specified using @XmlSchema.