我使用下面的代码来获取解组并通过Xpath查询unmarshelled对象。 我可以在取消编组后获取对象,但在XPath查询时,该值为空。EclipseLink Moxy unmarshall和getValueByXPath给出null
我是否需要指定任何NameSpaceResolver?
请让我知道,如果你正在寻找任何进一步的信息。
我的代码:
JAXBContext jaxbContext = (JAXBContext) JAXBContextFactory.createContext(new Class[] {Transaction.class}, null);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StreamSource streamSource= new StreamSource(new StringReader(transactionXML));
transaction = unmarshaller.unmarshal(streamSource, Transaction.class).getValue();
String displayValue = jaxbContext.getValueByXPath(transaction, xPath, null, String.class);
我的XML:
<Transaction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<SendingCustomer firstName="test">
</SendingCustomer>
</Transaction>
那么你的XPath表达式是什么? “值为空” - 是字符串null(未设置)还是空的? –