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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:00:41+00:00 2026-06-15T14:00:41+00:00

I have concatenation problem for multiple string tags in Sax Parser. My Xml Data

  • 0

I have concatenation problem for multiple string tags in Sax Parser.
My Xml Data look(huge list) like..

<Table diffgr:id="Table1" msdata:rowOrder="0">
<ID>213</ID>
<LastName>Sirk</LastName>
<FirstName>Thomas</FirstName>
<Height>6 ft 4 inches</Height>
<HomeTown>Glen St. Mary's</HomeTown>
<TeamName>Blue Devils</TeamName>
<Age>19</Age>
<FullName>1 Thomas Sirk</FullName>
</Table>

<Table diffgr:id="Table2" msdata:rowOrder="1">
<ID>17</ID>
<LastName>Vernon</LastName>
<FirstName>Conner</FirstName>
<Height>6 ft 1 inches</Height>
<HomeTown>Miami Fl</HomeTown>
<TeamName>Blue Devils</TeamName>
<Age>22</Age>
<FullName>2 Conner Vernon</FullName>
 </Table>

<Table diffgr:id="Table3" msdata:rowOrder="2">
<ID>203</ID>
<LastName>Crowder</LastName>
<FirstName>Jamison</FirstName>
<Height>5 ft 9 inches</Height>
<HomeTown>Monroe NC</HomeTown>
<TeamName>Blue Devils</TeamName>
<Age>19</Age>
<FullName>3 Jamison Crowder</FullName>
 </Table>

I used this code in handler like this.

class MyHandler extends DefaultHandler{

            boolean is_sno=false;
        boolean is_sname=false;
        boolean is_sclass=false;
        boolean is_sphno=false;
        boolean is_semail=false;
        boolean mIsSegment = false;
        int mCurrentIndex = -1;

            @Override
        public void startDocument() throws SAXException {
            // TODO Auto-generated method stub
            super.startDocument();
        }

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

             if (localName.equals("Table")) {
                    mCurrentIndex++;
                    al_sno.add("");
                    al_sname.add("");
                    al_sclass.add("");
                            al_sphno.add("");
                            al_semail.add("");
                }

             else if(localName.equals("ID")){
                is_sno=true;
            }
            else if(localName.equals("TeamName")){
                is_sname=true;
            }
            else if(localName.equals("Fullname")){
                is_sclass=true;
            }
            /*else if(localName.equals("HomeTown")){
                is_sphno=true;
            }
            else if(localName.equals("Height")){
                is_semail=true;
            }*/
        }

        @Override
        public void characters(char[] ch, int start, int length)
                throws SAXException {
            // TODO Auto-generated method stub
            super.characters(ch, start, length);
            if(is_sno){
                 al_sno.set(mCurrentIndex, new String(ch, start, length));
            }
            else if (is_sname) {
                if (!mIsSegment) {
                    al_sname.set(mCurrentIndex, new String(ch, start, length));
                } else {
                    al_sname.set(mCurrentIndex,
                            al_sname.get(al_sname.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            }
            else if(is_sclass){

            if (!mIsSegment) {
                al_sclass.set(mCurrentIndex, new String(ch, start, length));
            } else {
                al_sclass.set(mCurrentIndex,
                        al_sclass.get(al_sclass.size() - 1)
                                + new String(ch, start, length));
            }
            mIsSegment = true;
            }

        else if(is_sphno){
            if (!mIsSegment) {
                al_sphno.set(mCurrentIndex, new String(ch, start, length));
            } else {
                al_sphno.set(mCurrentIndex,
                        al_sphno.get(al_sphno.size() - 1)
                                + new String(ch, start, length));
            }
            mIsSegment = true;}
        }
        else if(is_semail){
            if (!mIsSegment) {
                al_semail.set(mCurrentIndex, new String(ch, start, length));
            } else {
                al_semail.set(mCurrentIndex,
                        al_semail.get(al_semail.size() - 1)
                                + new String(ch, start, length));
            }
            mIsSegment = true;}

        }
        }

        @Override
        public void endElement(String uri, String localName, String name)
                throws SAXException {
            // TODO Auto-generated method stub
            super.endElement(uri, localName, name);

            if(localName.equals("ID")){
                is_sno=false;
            }
            else if(localName.equals("TeamName")){
                is_sname=false;
                 mIsSegment = false;
            }
            else if(localName.equals("Fullname")){
                is_sclass=false;
                            mIsSegment = false;
            }
            else if(localName.equals("HomeTown")){
                is_sphno=false;
                           mIsSegment = false;
            }
            else if(localName.equals("Height")){
                is_semail=false;
                             mIsSegment = false;
            }
        }

        @Override
        public void endDocument() throws SAXException {
            // TODO Auto-generated method stub
            super.endDocument();
        }


    }

I trying to display the playerlist of team in one page but most of the strings getting Concatenation problem for Height,HomeTown,Fullname,TeamName. I followed some code here. It working fine for single string not for multiple. Please help me.

  • 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-06-15T14:00:42+00:00Added an answer on June 15, 2026 at 2:00 pm

    I’ve rewrote the handler for the SaxParser:

    // the Lists of data 
    ArrayList<String> mIdList = new ArrayList<String>();
    ArrayList<String> mLastNameList = new ArrayList<String>();
    ArrayList<String> mFirstNameList = new ArrayList<String>();
    ArrayList<String> mHeightList = new ArrayList<String>();
    ArrayList<String> mHomeTownList = new ArrayList<String>();
    ArrayList<String> mTeamNameList = new ArrayList<String>();
    ArrayList<String> mAgeList = new ArrayList<String>();
    ArrayList<String> mFullNameList = new ArrayList<String>();
    

    The MyHandler class:

    class MyHandler extends DefaultHandler {
    
        private boolean isIDTag = false;
        boolean isLastNameTag = false;
        boolean isFirstNameTag = false;
        boolean isHeightTag = false;
        boolean isHomeTownTag = false;
        boolean isTeamNameTag = false;
        boolean isAgeTag = false;
        boolean isFullNameTag = false;
        boolean mIsSegment = false;
        private int mCurrentIndex = -1;
    
        @Override
        public void startElement(String uri, String localName, String name,
                Attributes attributes) throws SAXException {
            if (localName.equals("Table")) {
                mCurrentIndex++;
                mIdList.add("");
                mLastNameList.add("");
                mFirstNameList.add("");
                mHeightList.add("");
                mHomeTownList.add("");
                mTeamNameList.add("");
                mAgeList.add("");
                mFullNameList.add("");
            } else if (localName.equals("ID")) {
                isIDTag = true;
            } else if (localName.equals("LastName")) {
                isLastNameTag = true;
            } else if (localName.equals("FirstName")) {
                isFirstNameTag = true;
            } else if (localName.equals("Height")) {
                isHeightTag = true;
            } else if (localName.equals("HomeTown")) {
                isHomeTownTag = true;
            } else if (localName.equals("TeamName")) {
                isTeamNameTag = true;
            } else if (localName.equals("Age")) {
                isAgeTag = true;
            } else if (localName.equals("FullName")) {
                isFullNameTag = true;
            }
        }
    
        @Override
        public void characters(char[] ch, int start, int length)
                throws SAXException {
            if (isIDTag) {
                // the ID
                mIdList.set(mCurrentIndex, new String(ch, start, length));
            } else if (isLastNameTag) {
                if (!mIsSegment) {
                    mLastNameList.set(mCurrentIndex, new String(ch, start,
                            length));
                } else {
                    mLastNameList.set(mCurrentIndex,
                            mLastNameList.get(mLastNameList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            } else if (isFirstNameTag) {
                if (!mIsSegment) {
                    mFirstNameList.set(mCurrentIndex, new String(ch, start,
                            length));
                } else {
                    mFirstNameList.set(mCurrentIndex,
                            mFirstNameList.get(mFirstNameList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            } else if (isHeightTag) {
                if (!mIsSegment) {
                    mHeightList.set(mCurrentIndex,
                            new String(ch, start, length));
                } else {
                    mHeightList.set(mCurrentIndex,
                            mHeightList.get(mHeightList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            } else if (isHomeTownTag) {
                if (!mIsSegment) {
                    mHomeTownList.set(mCurrentIndex, new String(ch, start,
                            length));
                } else {
                    mHomeTownList.set(mCurrentIndex,
                            mHomeTownList.get(mHomeTownList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            } else if (isTeamNameTag) {
                if (!mIsSegment) {
                    mTeamNameList.set(mCurrentIndex, new String(ch, start,
                            length));
                } else {
                    mTeamNameList.set(mCurrentIndex,
                            mTeamNameList.get(mTeamNameList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            } else if (isAgeTag) {
                if (!mIsSegment) {
                    mAgeList.set(mCurrentIndex, new String(ch, start, length));
                } else {
                    mAgeList.set(mCurrentIndex,
                            mAgeList.get(mAgeList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            } else if (isFullNameTag) {
                if (!mIsSegment) {
                    mFullNameList.set(mCurrentIndex, new String(ch, start,
                            length));
                } else {
                    mFullNameList.set(mCurrentIndex,
                            mFullNameList.get(mFullNameList.size() - 1)
                                    + new String(ch, start, length));
                }
                mIsSegment = true;
            }
        }
    
        @Override
        public void endElement(String uri, String localName, String name)
                throws SAXException {
            if (localName.equals("ID")) {
                isIDTag = false;
            } else if (localName.equals("LastName")) {
                isLastNameTag = false;
                mIsSegment = false;
            } else if (localName.equals("FirstName")) {
                isFirstNameTag = false;
                mIsSegment = false;
            } else if (localName.equals("Height")) {
                isHeightTag = false;
                mIsSegment = false;
            } else if (localName.equals("HomeTown")) {
                isHomeTownTag = false;
                mIsSegment = false;
            } else if (localName.equals("TeamName")) {
                isTeamNameTag = false;
                mIsSegment = false;
            } else if (localName.equals("Age")) {
                isAgeTag = false;
                mIsSegment = false;
            } else if (localName.equals("FullName")) {
                isFullNameTag = false;
                mIsSegment = false;
            }
        }
    
    }
    

    It should work now.

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

Sidebar

Related Questions

If I have a string like 11E12C108N which is a concatenation of letter groups
I have a List<List<String>> I need to get a List of all possible concatenation
Imagine the scenario you have a listing page that is a concatenation of multiple
I need help on concatenation. I have a Title which is displayed below like
there: I'm new to Perl, and get a string concatenation problem of it. I
I have the following xml document: <?xml version=1.0 encoding=UTF-8?> <root> <data> <child1>&#160;Well, some spaces
Background: I have a table with 5 million address entries which I'd like to
I have a CONCATENATION problem regarding quotes. In my database I have single and
EDIT: Ok I had a problem with one of the string concatenation functions, has
I am trying to create a concatenation of multiple images into one, but have

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.