How to parse a complex SOAP response in Android

谁都会走 提交于 2019-11-30 19:21:55

问题


Since two days I am trying to consume a WCF (.NET) Soap Service and serialize it's response without success. I am getting a correct response (I had to put it on pastebin: SOAP Response Example), but KSOAP2 is not able to handle .NET Datasets correctly. I already consultated various articles about this specific problem, but none has a .NET Dataset to handle. The main article which gave guideance was an article by IBM "Working with XML on Android"

I tried following steps to parse my data without success:

  1. Parsing with SAX (android) -> Seems not to work with this complex document because of the different namespaces.
  2. with DOM Object(android) -> NullPointerExeption (dooh!)
  3. with Digester (dom4j) -> NullPointerException (arggh!)
  4. method suggested by helloandroid.com "Using ksoap2 for android, and parsing output data"

Some questions: - The returned response is a normal XML, but actually it includes a .NET Dataset. Has anyone had success to parse data out of such a response? - Is there a way to make KSOAP2 not to trying to parse the data? It returns a rubbish SoapObject, which is unreadable. I would like just the contents of the SOAP body. Is there a way to intercept that? - Do you have any other hint?


回答1:


With ksoap2 you can set the envelope debugging to true and then get the response dump, which will contain the full xml.

However what makes you think that the SoapObject returned is unreadable. Check it out in a debugger and you will find that everything is there and you can just parse it out using getProperty("propname") and getAttribute("attribute) which in turn are either SoapObjects again if they are nested or contain actual values if they are leaf nodes.

Check out some of the links on the wiki to http://code.google.com/p/ksoap2-android/




回答2:


I have used DOM and SAX so far to parse XML documents. DOM had a few issues on Android and I had to handle some bugs in the API. SAX seems to be better (and leaner if you only read). I have not used ksoap, but did everything hand crafted. Though I am not sure where the problem with that .NET thing is, I wouldn't see an issue using SAX or DOM. Can you comment why you think SAX won't work because of namespaces? A.




回答3:


One of my solutions was: http://vtd-xml.sourceforge.net/

I hope someone will find something more suitable.




回答4:


I have the same problem. First I used vtd-xml. It was working without problems but it is a bit slow. Now I switched to standard Java SAX (not Android SAX implementation) and it works ok.



来源:https://stackoverflow.com/questions/4162598/how-to-parse-a-complex-soap-response-in-android

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