如何在java中解析来自SOAP响应消息的数据
我正在使用 Dom4j 来解析 SOAP 消息。我遇到了一个问题:
Node 节点 = document.selectSingleNode( "/*/soapenv:Envelope/soapenv:Body/ns:addResponse" );
当我使用上述 XPath 时,出现以下异常:
异常:XPath 表达式使用未绑定的命名空间前缀 ns1
我找到了执行此操作的方法:删除名称空间,但不建议这样做。
任何帮助将不胜感激。谢谢
顺便说一句,这项工作有更好的方法或工具包吗?
I am using Dom4j to parse SOAP message. I had a problem:
Node node = document.selectSingleNode( "/*/soapenv:Envelope/soapenv:Body/ns:addResponse" );
when I use the above XPath, I got the following exception:
Exception: XPath expression uses unbound namespace prefix ns1
I found ways to do this: remove namespace, which is not recommended.
Any help will be appreciated. Thanks
BTW, is there a better way or toolkit for this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个 org.dom4j.XPath 对象并向其附加合适的命名空间绑定。就像这样:
有更好的方法吗?嗯,现在有了 JAX-WS,如果您的服务有可用的 WSDL,那么为其生成 Java 接口和类通常会非常简单。
You need to create a org.dom4j.XPath object and attach suitable namespace bindings to it. Something like this:
Is there a better way? Well, these days there is JAX-WS, and if there is WSDL available for your service, it is usually very simple to generate Java interfaces and classes for it.