Search code examples
xpathjaxbmoxy

JAXB XPATH Element always empty


I've read a lot of exapmles, and also googled way to much - but still hasn't found the problem.

I'm wondering why my "name" - element is always empty, see result:

Category [id=1, name=
        , active=1]

My xml-File:

<category>
<id><![CDATA[1]]></id>
<active><![CDATA[1]]></active>
<name>
    <language id="1" xlink:href="http://www.somelinkhere.com/languages/1"><![CDATA[bla]]>/language>
</name>
</category>

my Java-Class:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
    public class Category {
            private String id;
            private String active;

            @XmlPath("name/language[@id='1']/text()")
            private String name;

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }
                    @Override
            public String toString() {
                return "PrestaCategory [id=" + id + ", name=" + name + ", active="
                        + active + "]";
            }...

I think it's a small meistake, but I can't find it...


Solution

  • The answer was pretty obvoious - it was necessary to create a jaxb.properties file within the package with this property:

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    after that it worked properly....