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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:07:30+00:00 2026-06-12T15:07:30+00:00

I am new to SAXParser, so please forgive me. How can I parse any

  • 0

I am new to SAXParser, so please forgive me.

How can I parse any XML file and convert it to List<XNode>?
Below is the structure of class XNode:

class XNode{

    private String nodeName;
    private String nodeValue;
    private List<XAttribute> attributes;
    private boolean isParentNode;
    private List<XNode> childNodes;
}

Also the structure of XAttribute:

class XAttribute{

    private String name;
    private String value;
}

By parsing any file, it should return the List objects.

So far, I have tried below code but don’t know, how to check and attach childNodes.

public class XmlProcesser extends DefaultHandler {
    XMLResponse xmlResponse = null;
    boolean endtag = false;

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        System.out.print("" + qName + "");
        if (attributes.getLength() == 0) {
        } else {
            for (int index = 0; index < attributes.getLength(); index++) {
                System.out.print(attributes.getLocalName(index) + " =  " + attributes.getValue(index));
            }
        }
    }

    @Override
    public void characters(char ch[], int start, int length) throws SAXException {
        String s = new String(ch, start, length);
        System.out.println(s);
        endtag = false;
    }

    @Override
    public void endElement(String uri, String localName,
            String qName) throws SAXException {
        endtag = true;
        System.out.print("  " + qName + "  ");

    }
}
  • 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-12T15:07:32+00:00Added an answer on June 12, 2026 at 3:07 pm

    One usual way to do this is by using a Stack and a notion of current node. When you encounter a startElement you do the following

    1. Create a new element child
    2. Add this child element to the current element
    3. Push the current element on the stack
    4. Make the child element the new current element.

    When you encounter endElement you do the reverse:

    1. Pop the top element from the stack and make the current element again.

    The bottom of the stack is the root.

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

Sidebar

Related Questions

I created an app to parse a XML file using SAXParser and the code
I'm trying to parse some xml and i'm getting a NullPointerException but i can't
How can I convert a List to an Array in Java? Check the code
URL url = new URL(http://www.site.com/1.xml); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLHandler
i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/ my
The below code calls the ReadXMLFile constructor ReadXMLFile r=new ReadXMLFile(small.xml); HashMap r=r.getrcset(); I am
I am working on RSS XML saxparser. I am creating the RSS list view
I'm creating an Android application that is supposed to use SAX (javax.xml.parsers.SAXParser) to parse
i want to parse a XAPI xml with the SAXParser. But now i have
new to c#. I'm trying to make a simple system where I can search

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.