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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:28:00+00:00 2026-05-30T19:28:00+00:00

Following is the XML structure – <Projects> <Project> <Name>Web Site Designing</Name> <Members> <MName>Jack</MName> <MName>John</MName>

  • 0

Following is the XML structure –

<Projects>
   <Project>
     <Name>Web Site Designing</Name>
     <Members>
        <MName>Jack</MName>
        <MName>John</MName>
        <MName>Jill</MName>
     </Members>
   </Project>
   <Project>
     <Name>Site Ranking</Name>
     <Members>
        <MName>Jack</MName>
        <MName>James</MName>
     </Members>
   </Project>
   <Project>
     <Name>E-Mailing</Name>
     <Members>
        <MName>Matt</MName>
     </Members>
   </Project>
<Projects>

What will be the XPath Query to get the following output in Java –

Web Site Designing,Jack,John,Jill
Site Ranking,Jack,James
E-Mailing,Matt

Right now the Java Code I am using is not doing the same. Pls find the java code below –

.......
.......
.......
String pName = "";
String mName = "";
Document doc = builder.parse("Project.xml");
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//Projects/Project");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
BufferedWriter out = new BufferedWriter(new FileWriter("projInfo.txt"));
Node node;
for (int i = 0; i < nodes.getLength(); i++) 
{
    node = nodes.item(i);
    pName = xpath.evaluate("Name",node);
    mName = xpath.evaluate("Members/MName",node);

    //Here's something worng
    out.write(pName + "," + mName + "\r\n");
}
out.close();
.......    

Have a nice day, JB

  • 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-30T19:28:02+00:00Added an answer on May 30, 2026 at 7:28 pm

    mName = xpath.evaluate(“Members/MName”,node);

    This returns a node-list, but in the next code line:

    out.write(pName + "," + mName + "\r\n"); 
    

    you are treating it as a single string.

    It would be correct to process all nodes contained in mName iterating through mName.

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

Sidebar

Related Questions

Hi I have the following XML structure: <Root> <Persons> <PersonList Category=Employee> <Person Name=John Id=5
I have the following XML structure: <agencies> <city> <name>New York</name> <address>Street A, 101</address> <phone>111-222-333</phone>
I have the following XML structure <root> <OuterLevel> <Node> <Name>NodeA</Name> </Node> <Node> <Name>NodeB</Name> <Node>
I am using the following XML structure <SERVERS> <SERVER NAME=A1 ID=1></SERVER> <SERVER NAME=A2></SERVER> <SERVER
I have the following XML structure: <node name=A> <node name=B> <node name=C/> <node name=D/>
I have the following XML structure: <row> <field name=Id>1</field> <field name=AreaId>1</field> <field name=Name>ת&quot;א</field> </row>
I have the following XML structure: <method constructor=true name=Main public=true> <parameterList/> <block> <call> <callAttrbute>
In my project, legacy code generates xml which has following structure : <Output> <Template
I have the following XML structure: <Capabilities> <Capability ID=1 Name=Capability # 1> <Relations> <Relation
I've got following XML structure: <artists> <artist> <name></name> <image size=small></image> <image size=big></image> </artist> </artists>

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.