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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:48:35+00:00 2026-05-26T07:48:35+00:00

I have a xml file that looks like this <a> <bb> <c date=20110706 time=1:20

  • 0

I have a xml file that looks like this

<a>
<bb>
<c date="20110706" time="1:20" name1="john" name2="jen" nick1="johnny" nick2="jenny" />
<c date="20110806" time="2:20" name1="steven" name2="judith" nick1="steve" nick2="judy" />
</bb>
</a>

I currently have it set to grab the attributes value and set them as strings based on the value of one attribute. using this code

try {
    String name1 = mName1;

    XPath xpath = XPathFactory.newInstance().newXPath();
    String expr = String.format("//a/bb/c[@* = '%s']", name1);
    Node c = null;
    try {
        c = (Node) xpath.evaluate(expr, xml, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

What I am trying to accomplish is have all c lines listed one after the other in the format below using textviews, notice I do not want the nick1 and nick2 included. I have been reading and testing for hours with arraylist and cant get the result I am looking for. This is how I want all of the c nodes in the xml to be listed each in a textview.

Date:20110706 – Time:1:20 – HisName:john – HerName: jen

Date:20110806 – Time:2:20 – HisName:steven – HerName: judith

Also would would it be possible to have an imageview next to each name per line?

Thank you in advance for any help you can provide, I have been trying to do this for hours with no luck its driving me crazy!

EDIT: by doing just “//a/bb/c” I get the first line of the xml with the information I want, but how do I move on to the next line, and so on?

  • 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-26T07:48:36+00:00Added an answer on May 26, 2026 at 7:48 am

    Specify a returnType of XPathConstants.NODESET as the second argument to evaluate and iterate the results:

    final XPath xpath = XPathFactory.newInstance().newXPath();
    final XPathExpression expr = xpath.compile("//a/bb/c");
    final NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        final NamedNodeMap attrs = nodes.item(i).getAttributes();
        final Node dateNode = attrs.getNamedItem("date");
        System.out.println(dateNode.getNodeName() + ":" + dateNode.getNodeValue());
    }
    

    I’ve shown the output for the date attribute only, but the others should be obvious from this example.

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

Sidebar

Related Questions

I have a very simple XML file, that looks like this: <Data><Day Num=4197> <Date>270611</Date>
--edited for clarity (hopefully) I have an XML file that looks something like this:
I have an eclipse's .classpath file that looks like this: <?xml version=1.0 encoding=UTF-8?> <classpath>
I have an xml file that looks like this: ... <e1> <e2> <e3>content1.1</e3> <e3>content1.2</e3>
I have an XML file that looks like this. <collections id=my collections> <category id=my
I have an xml file that looks like this; <Employee> <EmployeeName>Burt Reynolds</EmployeeName> <EmployeeTitle>Bad Ass</EmployeeTitle>
I have an XML file that looks like this: <?xml version=1.0? encoding=UTF-8 standalone=no?> <dir
I have an XML file that looks like this <library> <book> <title>Title</title> <author>author</author> <price>20</price>
I have an XML file that looks like this. <Almond> Roasted Almonds,Almond Extract,Almond Sauce,Almond
Basically I have an XML file that looks like this: <?xml version=1.0 encoding=UTF-8?> <data>

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.