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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:27:58+00:00 2026-06-11T14:27:58+00:00

I have used script below and the output is X value : 123 Y

  • 0

I have used script below and the output is
X value : 123
Y value : 123
X value : 123
Y value : 130

how can I set first X as X0; first Y as Y0 and second X as X1 and second Y as Y1 ? I used SAX parser, it has processed my input file properly, and now i want to define X0, X1, Y0, Y1 in order to draw line

public static void main(String argv[]) {

        try {

        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();

        DefaultHandler handler = new DefaultHandler() {

        boolean xele = false;
        boolean yele = false;


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

            if (qName.equalsIgnoreCase("X")) {
                xele = true;
            }

            if (qName.equalsIgnoreCase("Y")) {
                yele = true;
            }


        }
        public void characters(char ch[], int start, int length) throws SAXException {

            if (xele) {
                System.out.println("X value : " + new String(ch, start, length));
                xele = false;
            }

            if (yele) {
                System.out.println("Y value : " + new String(ch, start, length));
                yele = false;
            }


        }

         };

           saxParser.parse("c:\\input.xml", handler);

         } catch (Exception e) {
           e.printStackTrace();
         }

Thanks

  • 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-11T14:27:59+00:00Added an answer on June 11, 2026 at 2:27 pm

    You can declare arrays to hold the values of X and Y and an index to increment after storing the values every time characters method is called by the parser, in your DefaultHandler implementation and expose these arrays through getters. Alternatively, you can use collections like java.util.List/java.util.ArrayList to hold the values.

    public static void main(String argv[])
    {
        try
        {
    
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();
    
            MyDefaultHandler handler = new MyDefaultHandler();
            saxParser.parse("c:\\input.xml", handler);
            System.out.println(handler.getXList() + ", " + handler.getYList());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
    static class MyDefaultHandler extends DefaultHandler
    {
        private List<Integer> xList = new ArrayList<Integer>();
        private List<Integer> yList = new ArrayList<Integer>();
        boolean xele = false;
        boolean yele = false;
    
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
        {
    
            if (qName.equalsIgnoreCase("X"))
            {
                xele = true;
            }
    
            if (qName.equalsIgnoreCase("Y"))
            {
                yele = true;
            }
    
        }
    
        public void characters(char ch[], int start, int length) throws SAXException
        {
    
            if (xele)
            {
                System.out.println("X value : " + new String(ch, start, length));
                xele = false;
                xList.add(Integer.parseInt(new String(ch, start, length)));
            }
    
            if (yele)
            {
                System.out.println("Y value : " + new String(ch, start, length));
                yele = false;
                yList.add(Integer.parseInt(new String(ch, start, length)));
            }
        }
    
        public List<Integer> getXList()
        {
            return xList;
        }
    
        public List<Integer> getYList()
        {
            return yList;
        }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first post be gentle. I have the script below which was taken out
i have something similar to the following... used a python script to JSON to
I tweaked this script that I used from JqueryUi and I have a problem.
I have a function in java script, that I used it to take the
The script below is used to hide a paragraph until all text fields inside
I have a script I have used for quite a while that validates UK
I have query regarding Accordion tabs .. I have used Accordion Menu plugin Below
I have the script below and on the website http://cacrochester.com , sometimes the contents
Background: I have a jQuery validation script, which is used on almost all my
I have a number of scripts used to build a database. These need to

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.