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 6117633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:36+00:00 2026-05-23T15:20:36+00:00

When I parse following XML and store it in HashMap the message is cut

  • 0

When I parse following XML and store it in HashMap the message is cut after (‘) this symbol.

Ex. Message: “Hey amar! What’s up?”. it cut like this.

  • message =(3577): Hey amar! What
  • message =(3577): ‘
  • message =(3577): s up?

The final out put is : message = “s up?”

So how to solve this problem ?

HashMap’s for Shoring XML DATA :

public static HashMap<String,String> message_map1 = new HashMap<String,String>();
public static HashMap<String,String> message_map2 = new HashMap<String,String>();
public static HashMap<String,String> message_map3 = new HashMap<String,String>();

XML:

<statuses type="array">
 <status>
  <messageinfo>
    <messageid>485</messageid>
    <userid>58</userid>
    **<message>Hey amar! What's up?</message>**
  </messageinfo>
 <messageinfo>
    <messageid>486</messageid>
    <userid>58</userid>
    **<message>Hey What's up?</message>**
  </messageinfo>
 <messageinfo>
    <messageid>485</messageid>
    <userid>58</userid>
    **<message>What's up?</message>**
  </messageinfo>
 </status>
</statuses>

code:

package com.xmldataparser;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;

public class Message_XHandler extends DefaultHandler 
{
     boolean in_porf_msg_statuses;
     boolean in_prof_msg_status;
     boolean in_prof_msg_messageinfo;
     boolean in_prof_msg_messageid;
     boolean in_prof_msg_userid;
     boolean in_prof_msg_message;

    int i=0;
    public String key = "";
    public String value = "";

    XMLData xml_message;

    @Override
    public void startDocument() throws SAXException
    {
        super.startDocument();
        xml_message = new XMLData();
    }

    @Override
    public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException 
    {
        super.startElement(uri, localName, qName, attributes);

        if(localName.equalsIgnoreCase("statuses"))
        {
            in_porf_msg_statuses= true;
        }
        else if(localName.equalsIgnoreCase("status"))
        {
            in_prof_msg_status = true;
        }
        else if(localName.equalsIgnoreCase("messageinfo"))
        {
            in_prof_msg_messageinfo = true;
            i++;
        }
        else if(localName.equalsIgnoreCase("messageid"))
        {
            in_prof_msg_messageid = true;
        }
        else if(localName.equalsIgnoreCase("userid"))
        {
            in_prof_msg_userid = true;
        }
        else if(localName.equalsIgnoreCase("message"))
        {
            in_prof_msg_message = true;
        }
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException 
    {
        super.characters(ch, start, length);
        String chars = new String(ch,start,length);
        chars = chars.trim();

        else if(in_prof_msg_messageid)
        {   
            if(i==1)
                {
                    xml_message.message_map1.put("messageid", chars);
                }
            else if(i==2)
                 {
                xml_message.message_map2.put("messageid", chars);
                 }
            else if(i==3)
             {
                xml_message.message_map3.put("messageid", chars);
             }  
            Log.v("messageid = ", chars);
        } 
        else if(in_prof_msg_userid)
        {   
            if(i==1)
                {
                    xml_message.message_map1.put("userid", chars);
                }
            else if(i==2)
                 {
                xml_message.message_map2.put("userid", chars);
                 }
            else if(i==3)
             {
                xml_message.message_map3.put("userid", chars);
             }  

                Log.v("userid = ", chars);
        } 
        else if(in_prof_msg_message)
        {   
            if(i==1)
                {
                xml_message.message_map1.put("message", chars);
                }
            else if(i==2)
                 {
                    xml_message.message_map2.put("message", chars);
                 }
            else if(i==3)
                 {
                    xml_message.message_map3.put("message", chars);
                 }  

                Log.v("message = ", chars);

        } 


        } 


    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException 
    {
        super.endElement(uri, localName, qName);

        if(localName.equalsIgnoreCase("statuses"))
        {
            in_porf_msg_statuses = false;
        }

        else if(localName.equalsIgnoreCase("messageinfo"))
        {
            in_prof_msg_messageinfo = false;
        }
        else if(localName.equalsIgnoreCase("messageid"))
        {
            in_prof_msg_messageid = false;
        }
        else if(localName.equalsIgnoreCase("userid"))
        {
            in_prof_msg_userid= false;
        }
        else if(localName.equalsIgnoreCase("message"))
        {
            in_prof_msg_message = false;
        }
    }

    @Override
    public void endDocument() throws SAXException
    {
        super.endDocument();
    }

    public XMLData getProfileMessageData()
    {
        Log.v("WHERE","Message_XHandler getProfileMessageData()");
        return xml_message;
    }
}

Problem :
Log:
07-04 13:38:37.924: VERBOSE/message =(3577): Hey amar! What
07-04 13:38:37.934: VERBOSE/message =(3577): ‘
07-04 13:38:37.934: VERBOSE/message =(3577): s up?

  • 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-23T15:20:36+00:00Added an answer on May 23, 2026 at 3:20 pm

    As Don Roby Answered..

    Take a String variable and add in your map at endElement() method where your in_message variable goes false.
    For Example do this…

    String str = "";
    

    //In characters() Method
    else if(in_message)
    {
    str += chars;
    }
    //In endElement() Method

    else if(localName.equalsIgnoreCase(“message”))
    {
    in_message = false;
    map.put(“message”, str);
    Log.i(“map “+i,” message = “+str);
    str = “”;
    }
    `

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

Sidebar

Related Questions

I am trying to parse the following XML file in Java and to store
I'm getting a XML responde like this: xml = grails.converters.XML.parse( new URL( 'http://...) )
I want to parse the following XML document to resolve all entities in it:
Using Castor to parse the following xml into POJOs using a mapping file is
I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
So I'm trying to parse the following XML document with C#, using System.XML: <root
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
I am using SAX to parse some XML. Let's say I have the following
I'd like to be able to parse the following structure: blah { string-1, string-2,
I have the following XML file and I want to store it using the

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.