Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3977952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:59:08+00:00 2026-05-20T04:59:08+00:00

I have a SOAP web service that returns an XML in this format <SOAP-ENV:Envelope

  • 0

I have a SOAP web service that returns an XML in this format

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:GetResponse>
      <ret SOAP-ENC:arrayType="ns2:Map[2]" xsi:type="SOAP-ENC:Array">
         <item xsi:type="ns2:Map">
           <item>
              <key xsi:type="xsd:string">ProtocolId</key>
              <value xsi:type="xsd:string">1</value>
           </item>
           <item>
              <key xsi:type="xsd:string">Title</key>
              <value xsi:type="xsd:string">Some Title</value>
           </item>
           <item>
              <key xsi:type="xsd:string">Text</key>
              <value xsi:type="xsd:string"> Some Text </value>
           </item>
         </item> 
         <item xsi:type="ns2:Map">
           <item>
              <key xsi:type="xsd:string">ProtocolId</key>
              <value xsi:type="xsd:string">2</value>
           </item>
           <item>
              <key xsi:type="xsd:string">Title</key>
              <value xsi:type="xsd:string">Another Title</value>
           </item>
           <item>
              <key xsi:type="xsd:string">Text</key>
              <value xsi:type="xsd:string">Another Text </value>
           </item>
         </item> 
      </ret>
   </ns1:GetResponse>
 </SOAP-ENV:Body>

How to write a parser for this kind of XML. If you have some examples, it will be of great help.

Thanks

Mukul

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:59:09+00:00Added an answer on May 20, 2026 at 4:59 am

    I made it work with this parser –

    public class XmlPullFeedParser extends BaseFeedParser {
    public XmlPullFeedParser(String feedUrl) {
        super(feedUrl);
    }
    
    StringBuilder builder = new StringBuilder();
    int whichItemFlag = 0;
    
    Context thisContext;
    
    DataBaseHelper myDB;
    
    public void parse(InputStream is, Context context, String insertInto) {
    
        XmlPullParser parser = Xml.newPullParser();
    
        thisContext = context;
        myDB = new DataBaseHelper(thisContext);
        try {
            // auto-detect the encoding from the stream
            parser.setInput(is, "UTF-8");
            int eventType = parser.getEventType();
            boolean done = false;
            while (eventType != XmlPullParser.END_DOCUMENT && !done) {
                String name = null;
                String attr = null;
                switch (eventType) {
                case XmlPullParser.START_DOCUMENT:
                    break;
                case XmlPullParser.START_TAG:
                    name = parser.getName();
                    attr = parser.getAttributeName(0);
                    if (name.equalsIgnoreCase(ITEM)) {
                        if(attr!=null) {
                            builder.append("(");
                        }
                        whichItemFlag++;
                    } else if (name.equalsIgnoreCase(VALUE)) {
                        builder.append("'"+parser.nextText().replaceAll("'", "&#39;")+"',");
                    } 
                    break;
                case XmlPullParser.END_TAG:
                    name = parser.getName();
                    if (name.equalsIgnoreCase(ITEM)) {
                        whichItemFlag--;
                        if(whichItemFlag==0) {
                            builder.delete(builder.length()-1, builder.length());
                            builder.append(")");
                            writeStringToDb(insertInto, builder.toString());
                            builder.delete(0, builder.length());
                        }
                    } 
                    break;
                }
                eventType = parser.next();
            } 
        } catch (Exception e) {
            e.printStackTrace();
    //          throw new RuntimeException(e);
        } finally {
            myDB.close();
        }
    }
    
    private void writeStringToDb(String insertInto, String string) {
        SQLiteDatabase db = myDB.getWritableDatabase();
        String sql = insertInto + string;
        db.execSQL(sql);
        db.close();
    }
    

    The Stringbuilder i have used to create a string out of the values returned by the XML and use this string directly to write to the database. The parse method takes an inputstream, the application context and a string that helps me build the sql statement. From the parser itself i write directly to the database. Since the XML was very large (7MB), i had to do it this way otherwise my android device would run out of memory while building 1500+ objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WebService that returns XML in a SOAP response: <?xml version=1.0 encoding=utf-8
I have a web service that returns following type: <xsd:complexType name=TaggerResponse> <xsd:sequence> <xsd:element name=msg
I have a web service that returns the binary array of an object. Is
I'm planning an XML web service that takes an XML request and returns an
We currently have a SOAP based web service that our in house applications use
I have a REST web service that returns a structure containing an array of
I have a simple web service method that returns a simple java class as
We have SOAP web services in production that are relying on SOAP Headers (containing
I have been studying SOAP and WSDL in preparation for implementing a web service.
I have a web service that I want to access when it is added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.