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

  • Home
  • SEARCH
  • 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 6208601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:50:09+00:00 2026-05-24T05:50:09+00:00

I have an XML file with this structure: <?xml version=1.0> <person> <element att1=value1 att2=value2>Anonymous</element>

  • 0

I have an XML file with this structure:

<?xml version="1.0">
<person>
    <element att1="value1" att2="value2">Anonymous</element>
</person>

How can I extract the attributes names and values using wathever you want.

I tried JDOM, but I still can’t find a way to get the attributes from the element.

Element root = doc.getRootElement();
List allChildren = root.getChildren();
Iterator i = listEtudiants.iterator();
while(i.hasNext())
{
    Element current = (Element)i.next();
    System.out.println(current.getChild("elementName").getText());
    // this let me get just the value inside > anf </
    // so, if it's can be done by completing this code
    // it will be something like current.getSomething()
}

EDIT: I’m still having a problem with this file. I can’t reach foo attribute and its value moo.

<?xml version="1.0" encoding="UTF-8"?>
<person>
   <student att1="v1" att2="v2">
      <name>Michel</name>
      <prenames>
         <prename>smith</prename>
         <prename>jack</prename>
      </prenames>
   </student>
   <student classe="P1">
      <name foo="moo">superstar</name>
   </student>
</person>
  • 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-24T05:50:10+00:00Added an answer on May 24, 2026 at 5:50 am

    If you do know the name of the attribute, then you can use getAttributeValue to obtain its value:

    current.getAttributeValue("att1"); // value1
    

    If you do not know the name of the attribute(s), then you can use getAttributes() and iterate over each Attribute:

    List attributes = current.getAttributes();
    Iterator it = attributes.iterator();
    while (it.hasNext()) {
      Attribute att = (Attribute)it.next();
      System.out.println(att.getName()); // att1
      System.out.println(att.getValue()); // value1
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file that contains in products. File's structure this: <?xml version=1.0
I have this XML structure: <?xml version=1.0 encoding=utf-8?> <Request> <RequestHeader requestType=CreateUserRequest dateTime=2011-08-01T16:50:25.9387377+10:00 /> <RequestBody>
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an XML file, which I open in F# like this: let Bookmarks(xmlFile:string)
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have an XML file which contains lists of stores, a simplified version is
I have a directory of very large XML files with a structure as this:
Lets say I have this XML file: <weather> <temp>24.0</temp> <current-condition iconUrl=http://....>Sunny</current-condition> </weather> I'm trying

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.