0
<parent>         
  <child1>FIN </child1>
  <child2>Age 13</child2>
  <child3>Chennai</child3>
</parent>
<parent>
  <child1>FRE</child1>
  <child2>Age 15</child2>
  <child3>Delhi</child3>
</parent>

This is the XML which I am using. I need to get a value child3 node if my child1 node is matches in Java code. If FIN is matches, I need to get a value of child3 "Chennai". I'm using DoumentBuilderFactory to read XML. Help me to solve this logic.looking for a Java coding.

for( int i = 0; i< PatientVariables.length; i++){
  // loop the staff child node
  NodeList patientlist = PatientVariables[i].getChildNodes();

  for (int i = 0; i < patientlist.getLength(); i++) {
    Node node = patientlist.item(i);
Azametzin
  • 5,223
  • 12
  • 28
  • 46

1 Answers1

0

If your complete XML looks like that (please note I've added the root element and deleted the space after FIN for simplicity)

<root>
       <parent>         
       <child1>FIN</child1>
       <child2>Age 13</child2>
       <child3>Chennai</child3>
       </parent>
       <parent>
       <child1>FRE</child1>
       <child2>Age 15</child2>
       <child3>Delhi</child3>
       </parent>
</root>

you can find the element you are looking for by xpath: //parent/child1[text()='FIN']/following-sibling::child3

INDIVIDUAL-IT
  • 426
  • 3
  • 11