开发者

How to parse a complex SOAP response in Android

开发者 https://www.devze.com 2023-01-24 12:37 出处:网络
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

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 lik开发者_高级运维e just the contents of the SOAP body. Is there a way to intercept that? - Do you have any other hint?


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/


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.


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

I hope someone will find something more suitable.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号