我无法使用XMLBeam正确读取XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:storeTokenResponse xmlns:ns1="http://recurring.services.adyen.com">
<ns1:result>
<additionalData xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<alias xmlns="http://recurring.services.adyen.com">ALIAS</alias>
<aliasType xmlns="http://recurring.services.adyen.com">Default</aliasType>
<params xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<pspEchoData xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<pspReference xmlns="http://recurring.services.adyen.com">PSPREFERENCE</pspReference>
<recurringDetailReference xmlns="http://recurring.services.adyen.com">RECURRINGDETAILREFERENCE</recurringDetailReference>
<redirectType xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<redirectUrl xmlns="http://recurring.services.adyen.com" xsi:nil="true" />
<result xmlns="http://recurring.services.adyen.com">RESULT</result>
</ns1:result>
</ns1:storeTokenResponse>
</soap:Body>
给定的Java类:
public interface PaymentResponse {
@XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:alias")
String getAlias();
@XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:recurringDetailReference")
String getRecurringDetailReference();
@XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:pspReference")
String getPspReference();
@XBRead("/soap:Envelope/soap:Body/ns1:storeTokenResponse/ns1:result/ns1:result")
String getResult();
}
我是这样做的:
final PaymentResponse paymentResponse = new XBProjector.onXMLString(xml).read(PaymentResponse.class);
Assert.assertTrue("ALIAS",paymentResponse.getAlias());
是的,正如我测试的那样,正确的XPath是ns1:alias
。
但看起来XMLBeam没有正确识别这些值。 有人可以帮忙吗?