3

I want to see if a theme element exists with specified name in the following xml file.

input.xml

<data>
    <artifacts>
        <document id="efqw4eads">
            <name>composite</name>
        </document>
        <theme id="1">
            <name>Terrace</name>
        </theme>
        <theme id="2">
            <name>Garage</name>
        </theme>
        <theme id="3">
            <name>Reception</name>
        </theme>
        <theme id="4">
            <name>Grade II</name>
        </theme>
    </artifacts>
</data>

I have the following code. return true statement of the method is never executed. answer always contains a null value.

public boolean themeExists(String name, Data data){
    String expression = "artifacts/theme[name='"+name+"']/name/text()";
    String answer = jaxbContext.getValueByXPath(data, expression, null, String.class);
    if(answer == null || answer.equals("")){
        return false;
    }
    return true;
}
4

2 回答 2

1

There is no <artifacts/> element you're look for in the first axis step. Your XPath expression should be something like

String expression = "data/theme[name='"+name+"']/name/text()";
于 2013-07-26T13:28:44.200 回答
1

This use case isn't currently supported by EclipseLink JAXB (MOXy). I have opened the following enhancement you can use to track our progress:

于 2013-07-26T15:53:43.907 回答