1

I use MOXy's @XmlPath("/foo/bar[@baz]").

Elsewhere in the app I need XSLT 2.0 so I included Saxon HA 9.5 on my classpath. But that caused the XPath fail (doesn't find the nodes, unlike JDK's implementation).

How can I set for MOXy which XML / XPath impl to use?

Currently I use jaxb.properties next to JAXB bean's .class, but I'm okay to create the marshaller with some factory options or such.

Bonus question: I think the problem with XPath is that the XML file uses namespaces, <deployment xmlns="urn:jboss:bean-deployer:2.0"> ...
How can I make Saxon ignore namespaces in XPath? (without rewriting the XPath expression).

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
  • Hi, Thanks for this question. actually, I am also trying to do something similar but for some reason, it's not working as expected. I tried the things mentioned in this answer as well. I tried this approach and the example from the authors blog but still the `JAXB Marshalling` does not work as expected with `@XmlPath`. Seems like the XML produced with and without `@XmlPath` are the same. Can you please once look into this example and provide your answer: https://stackoverflow.com/questions/67500565/xmlpath-has-no-impact-during-the-jaxb-marshalling – BATMAN_2008 May 12 '21 at 10:28

2 Answers2

1

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.

bdoughan
  • 147,609
  • 23
  • 300
  • 400
1

For the record, this wasn't MOXy related. It was my code using XPath. So I ended up with

//XPathFactory xpf = XPath xp = XPathFactory.newInstance();
//XPathFactory xpf = new net.sf.saxon.xpath.XPathFactoryImpl();
XPathFactory xpf = new com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl();

This will complain

com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl is internal proprietary API and may be removed in a future release

but works.

Regarding namespaces, here's a discussion on ignoring namespaces.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
  • 1
    You can eliminate the "internal proprietary API" warning by passing the `-XDignore.symbol.file` command-line option to javac. (Doing so is not recommended, though.) – mernst Oct 24 '13 at 23:53