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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:15:07+00:00 2026-06-08T12:15:07+00:00

I have a xml file as follows <Moves> <Move name=left> <Coord X=100 Y=100/> <Coord

  • 0

I have a xml file as follows

<Moves>
  <Move name="left">
     <Coord X="100" Y="100"/>
     <Coord X="50" Y="100"/>
  </Move>
  <Move name="right">
     <Coord X="10" Y="80"/>
     <Coord X="40" Y="90"/>
  </Move>
<Moves> 

I am parsing it in Java using SAX Parser. the following two methods parse it basically

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {

                if (qName.equalsIgnoreCase("Coord")){
                    X = Integer.parseInt(attributes.getValue("X"));
                    Y = Integer.parseInt(attributes.getValue("Y"));
                } else if (qName.equalsIgnoreCase("Move")) {
                    move_points.clear();
                    move_name = attributes.getValue("name");
                }
            }

            /* If the read element is Move, add a MoveList with the name and if it is
             * a Coord, create a Point with it.
             */
            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {

                if (qName.equalsIgnoreCase("Coord")){
                    move_points.add(new Points(X, Y));
                } else if (qName.equalsIgnoreCase("Move")) {
                    moves_list.add(new MovesList(move_name, move_points));
                }
          }

I have an ArrayList move_points that stores all the coords read and an Arraylist moves_list that stores the moves name and their coords (which is an arraylist – move_points here)

The problem i am having is that when the document is parsed all the elements that are inside moves_list have the correct name but the entry in move_points or the coord stored are that of the last move in the XML file.

when i am checking what is being entered into moves_list in endElement method after each element Move, it shows the correct coord being entered into moves_list but when the whole document is parsed and i view what is inside moves_list after the root element Moves has been parsed, i am getting moves_list with all the coords of that of the last move.

Please help me out.

PS. moves_list is a public static variable

MovesList Class

public class MovesList {

private ArrayList<Points> move_points;
private String move_name;

public MovesList (String move_name, ArrayList<Points> move_points) {
    this.move_name = move_name;
    this.move_points = move_points;
}

public String getName(){
    return move_name;
}

public ArrayList<Points> getPoints(){
    return move_points;
}

}

Points Class

public class Points extends Point {

private int X;
private int Y;

public Points (int X, int Y) {
    this.X = X;
    this.Y = Y;
}

public Points (Points p) {
    X = p.getIntX();
    Y = p.getIntY();
}

public int getIntX () {
    return X;
}

public int getIntY () {
    return Y;
}

}
  • 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-08T12:15:09+00:00Added an answer on June 8, 2026 at 12:15 pm

    I think that your problem is that you don’t create a new move_points object. So this:

    } else if (qName.equalsIgnoreCase("Move")) {
      move_points.clear();
      move_name = attributes.getValue("name");
    }
    

    Should be this:

    } else if (qName.equalsIgnoreCase("Move")) {
      move_points = new ArrayList<Points>(); // note difference
      move_name = attributes.getValue("name");
    }
    

    Otherwise each MovesList object will have a move_points variable that refers to the same object.

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

Sidebar

Related Questions

I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I have my XML File as follows: <states> <state name =Alaska> <Location Name=loc1> <Address>testadd1</Address>
I have an integer array in an xml file as follows <integer-array name=myArray> <item>@drawable/pic1</item>
Hi all i have my XML file as follows Name of XML XMLFile2.xml <?xml
i have a XML file as follows: <?xml version=1.0 encoding=utf-8 ?> <publisher> <name>abc</name> <link>http://</link>
I have an XML file as follows, and I'm trying to read the content
I have an XML file from which I am parsing some content to display
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have an XML file as follows. When I use getElementsByTagName(LEVEL2_ID) , I do
I would like to have an xml config file as follows: <?xml version=1.0 encoding=utf-8

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.