Apache AXIS Ignore/Skip additional element while parsing

时光总嘲笑我的痴心妄想 提交于 2019-12-10 13:13:10

问题


We consume the web service of third party. Whenever they update the XML schema like add the new element we got the following error message.

"SAXException: Invalid Element ... "

Is there any way in AXIS to ask skip the additional element received on XML while parsing it?

I have generated web service client using AXIS earlier i used to receive XML as below

<Flight>
   <AirlineCode>AB</AirlineCode> 
</Flight>

and everything was working fine. But now i am getting an additional tag in response.

<Flight>
   <AirlineCode>AB</AirlineCode> 
   <OtherCode>XX</OtherCode> 
</Flight>

And for that i am getting "Invalid Element" Exception.

Thanks


回答1:


Apache Axis2 version 1.7.0-SNAPSHOT has the ability to ignore unexpected elements by compiling with the -Eiu switch.

Downloads for 1.7.0-SNAPSHOT




回答2:


Daniel's answer should help, but be aware that the output you get from Axis2 is very different from what you get from Axis so you will probably have to rewrite your integration somewhat. Also, the link he provided is for a subset of Axis2.

You're going to need the whole shebang for it to work and that's available here since, as of this writing, I couldn't find this release managed on any maven repositories: https://repository.apache.org/content/groups/snapshots/org/apache/axis2/axis2/1.7.0-SNAPSHOT/

Because this version is not managed in maven right now figuring out the dependencies is a big pain. Here's a snapshot of the gradle dependencies I used:

compile 'org.apache.ws.commons.schema:XmlSchema:1.4.7'
compile 'org.apache.ws.commons.axiom:axiom-api:1.2.15'
compile 'org.apache.neethi:neethi:3.0.1'
compile 'axis:axis-wsdl4j:1.6.3'
compile 'commons-logging:commons-logging:1.1.1'
compile files('C:\\temp\\wsdl\\axis2-1.7.0-SNAPSHOT.jar', 'C:\\temp\\wsdl\\axiom.jar')
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'

The axiom dependency was something I had to download manually because trying to use the repository managed version was not working for reasons that aren't clear to me.

All this aside, if you're not married to the Axis technology stack I would recommend avoiding it and instead integrating with a dynamic WSDL to Java framework that can accommodate WebServices whose Schema structure could change.



来源:https://stackoverflow.com/questions/12597558/apache-axis-ignore-skip-additional-element-while-parsing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!