2

I have an old API that I want to implement in my Android app. There is an existing older android app that uses apache's HttpPost class org.apache.http.client.methods.

The response format of the API is given below:

<?xml version='1.0' encoding='UTF-8' ?>
<root>
  <status>OK</status>
  <items>
    <item>
      <refno>123456</refno>
      <vehicle_name>BMW</vehicle_name>
      <model>BM1234</model>
      <color>BLACK</color>
    </item>
  </items>
</root>

Is it a pure SOAP library? Because after hours of research, I found the actual SOAP response to include wsdl tags but the response in this API is simple. Please suggest me how would I implement this API in my android application.

viper
  • 1,836
  • 4
  • 25
  • 41
  • 2
    This seems more like a normal non-SOAP-API that just returns something formatted with XML. – dan1st Jun 10 '21 at 05:37
  • 1
    This is a custom XML document; nothing to do with SOAP. Just parse it with your favorite XML parser. – Olivier Jun 11 '21 at 10:28

2 Answers2

2

SOAP and REST are not so different. It's just http requests. As dan1st mentioned, simply make a GET request for the XML then parse it. You can find tutorials for using SAX like this one:

https://www.tutlane.com/tutorial/android/android-xml-parsing-using-sax-parser

samael
  • 2,007
  • 1
  • 16
  • 34
2

SOAP is XML protocol for describing objects. While it works over many different protocols, using it over HTTP is basically XML over HTTP with a few extras settings required (usually HTTP Headers) to make it work.

WSDL is metadata that is used to describe the web services hosted on a given endpoint well enough that it is machine readable. Many client generation libraries for Web Services exist that can create a client that can call the web services.

If you can already call the web service endpoint and get a response using the apache client, then you can more or less ignore WSDL and all that stuff. You are doing enough SOAP to invoke the Web Service.

Once you get the response, deserialise / parse the XML using your favourite XML library.

Android has a couple built in, you can do it the old fashioned way with the DOM, use a library built on top of the DOM like dom4j or even the really old fashioned way with SAX.

For really big XML messages you want to use a streaming parser like Stax, but generally the DOM is easier to get going.

Finally write your own and make sure you add an answer to this SO Question :)

stringy05
  • 6,511
  • 32
  • 38