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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:35:32+00:00 2026-05-28T02:35:32+00:00

I am trying to parse data from a xml page through sax parsing technique.The

  • 0

I am trying to parse data from a xml page through sax parsing technique.The structure of the xml page is

<?xml version="1.0" encoding="UTF-8"?>
<news_magazine>
    <latest_news>
        <news>
            <category_id>5</category_id>
            <author>Super Admin</author>
        </news>
        <news>
            <category_id>6</category_id>
            <author>user</author>
        </news>
    </latest_news>
    <categories>
        <category>
            <category_id>5</category_id>
            <category_name>cricket</category_name>
        </category>
        <category>
            <category_id>5</category_id>
            <category_name>cricket</category_name>
        </category>
    </categories>
</news_magazine>

Both the news tag and category tag contains category id.How can i take the the category id separately?

  • 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-28T02:35:32+00:00Added an answer on May 28, 2026 at 2:35 am

    Hey you can do this in very simple way. Just maintain a extra variable
    when you put conditions in the parser when you get any of “news” or “category” tag than assign that in current_parent.
    and when comparing the tag “category_id” than also put condition of current_parent

    public static String current_parent;
    public void startElement(String namespaceURI, String localName, 
                String qName, Attributes atts) {
        if (localName.equals("news") {
              current_parent = "news";
            // Do your code with news.
            return;
        }
        else  if (localName.equals("category") {
              current_parent = "category";
            // Do your code with category.
            return;
        }
         else  if (localName.equals("category_id") {
             if(current_parent.equals("category")
                {
            // Do your code with category's category_id.
                 }else if(current_parent.equals("news")
                   {
            // Do your code with news's category_id.
                 }
            return;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse the output from a tool into a data structure but
I am trying to load data from XML string into a structure of some
I am trying to parse data from a xml web service but I am
I trying to parse xml from an inputstream using the sax parser. The inputstream
I'm trying to parse UTF-8 XML file and save some parts of it to
I'm getting the following error when trying to add some data from myXml.xml to
Ok I am trying to parse an XML from a get request in Javascript.
I am trying to launch a background thread to retrieve XML data from a
I'm trying to parse data from Archive.org's search functionality. The data looks like this:
I am trying to extract some data from an XML input with 6 lines,

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.