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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:37:17+00:00 2026-06-13T15:37:17+00:00

I have an xml which consists of elements xx and xxt. Each xxt contains

  • 0

I have an xml which consists of elements xx and xxt. Each xxt contains one or more xx elements. Each xx has an “cap” and “act” attributes. What I need to do is put all the cap-act values stored in a map.

Now note that my xml can contain 0 or an indefinite number of xxt. Thus, this should be done recursively. For now, I just did the simple parse when there are no xxt elements :

  for (Element element: (List<Element>) minfo.elements()) {
        if (element.getName().equals("xx")) {
            String cap = element.attributeValue("cap").trim();
            String act = element.attributeValue("act").trim();
            map.put(cap,act);
        }
        else if(element.getName().equals(xxt)){
            //TODO recursive method 
        }
    }

An example of xml could be like this:

    <xx cap="Min" act="act1"/>
    <xx cap="Ver" act="asd" />
    <xx cap="Tan" act="fw" />
    <xxt id="PR" cap="A">
      <xx cap="tY" act="ate" />
      <xx cap="Tn" act="bga" />
      <xx cap="Tn" act="sga" />
      <xxt cap="an" act="y34" />
          <xx cap="Miu" act="sahg"/>
      </xxt>
    </xxt>
    <xx cap="Mzt" act="act1"/>
  • 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-13T15:37:18+00:00Added an answer on June 13, 2026 at 3:37 pm

    You simply need to create a method which takes in parameter the node to analyze and go through its children.

    When a ‘xx’ is found, it is added to the map.
    When a ‘xxt’ is found, you call the function by passing the ‘xxt’ node as parameter.

    public function void analyze(Element element) {
        for (Element child : (List<Element>) element.elements()) {
            if (child.getName().equals("xx")) {
                String cap = child.attributeValue("cap").trim();
                String act = child.attributeValue("act").trim();
                map.put(cap,act);
            } else if(child.getName().equals("xxt")){
                analyze(child);
            }
        }
    }
    
    // To start recursivity
    analyze(minfo);
    

    This code won’t compile but it is to give you an example.

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

Sidebar

Related Questions

I have one XML request which I need to modify (to XML) and then
Hi I have big xml file which has a structure similar to the one
I have an xml document which consists of a number of the following: -
I have some XML which contains records and sub records, like this: <data> <record
I have a xml file which I need to open with Microsoft Word 2007.
I have this xml file which has text init. i.e Hi my name is
I have a very large (7GB) MediaWiki XML dump, which consists of records of
There is a requirement to have not-so-trivial dynamic list, each record of which consists
I have an XML file which consists of multiple records and I want to
I have a file, which is in XML format (consists just of root start

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.