我使用下面的代碼來獲取解組並通過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(未設置)還是空的? –