Issues retrieving repeated child nodes using XPath using Java












0















I have the below structure where parent nodes are repeating nodes - lets say 5 nodes. Within these 5 parent nodes, I have 5 repeating child nodes with 5 attributes. I need to retrieve the values of attributes depending upon the value of the attribute.



Lets say one of the attribute values is "Credit card" for one of the rows and for the other 4 rows value of the attribute value is "Debit card". When the value == "Credit card", I need to take the values of the other attributes. I have tested that only one row exists for attribute value == "Credit card" and at least one row exists for the attribute value == "Debit card"



So basically I need to get a hold of the 5 child nodes for each instance of the parent.



I am able to retrieve the 5 instance of parent nodes with the right XPath, but I retrieve the child nodes using the getchild() method, but I get child nodes as 25 (in case if we have 5 parent nodes - 5 * 5) but instead of 5 nodes. Basically, I am unable to get a hold of child nodes (count 5) . Whatever way I use, I always retrieve all child nodes under all parent nodes, instead of a particular parent node.



<Parent1>
<child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1>
<child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2>
<child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3>
<child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>
<child5>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child5>
</Parent1>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent2>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent3>
<Parent4>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent4>
<Parent5>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent5>









share|improve this question

























  • Kindly suggest how can we handle xpath using java. I wish to avoid using xmlapth as I have already done 99% of my code using xpath . I wish to avoid to switching to xmlpath .I would be thankful for solution towards this issue.

    – aditya mandlekar
    Nov 23 '18 at 2:36











  • XML structure incase its not posted incorrectly above:<Parent1> <child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1> <child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2> <child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3> <child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>

    – aditya mandlekar
    Nov 23 '18 at 2:40


















0















I have the below structure where parent nodes are repeating nodes - lets say 5 nodes. Within these 5 parent nodes, I have 5 repeating child nodes with 5 attributes. I need to retrieve the values of attributes depending upon the value of the attribute.



Lets say one of the attribute values is "Credit card" for one of the rows and for the other 4 rows value of the attribute value is "Debit card". When the value == "Credit card", I need to take the values of the other attributes. I have tested that only one row exists for attribute value == "Credit card" and at least one row exists for the attribute value == "Debit card"



So basically I need to get a hold of the 5 child nodes for each instance of the parent.



I am able to retrieve the 5 instance of parent nodes with the right XPath, but I retrieve the child nodes using the getchild() method, but I get child nodes as 25 (in case if we have 5 parent nodes - 5 * 5) but instead of 5 nodes. Basically, I am unable to get a hold of child nodes (count 5) . Whatever way I use, I always retrieve all child nodes under all parent nodes, instead of a particular parent node.



<Parent1>
<child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1>
<child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2>
<child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3>
<child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>
<child5>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child5>
</Parent1>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent2>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent3>
<Parent4>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent4>
<Parent5>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent5>









share|improve this question

























  • Kindly suggest how can we handle xpath using java. I wish to avoid using xmlapth as I have already done 99% of my code using xpath . I wish to avoid to switching to xmlpath .I would be thankful for solution towards this issue.

    – aditya mandlekar
    Nov 23 '18 at 2:36











  • XML structure incase its not posted incorrectly above:<Parent1> <child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1> <child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2> <child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3> <child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>

    – aditya mandlekar
    Nov 23 '18 at 2:40
















0












0








0








I have the below structure where parent nodes are repeating nodes - lets say 5 nodes. Within these 5 parent nodes, I have 5 repeating child nodes with 5 attributes. I need to retrieve the values of attributes depending upon the value of the attribute.



Lets say one of the attribute values is "Credit card" for one of the rows and for the other 4 rows value of the attribute value is "Debit card". When the value == "Credit card", I need to take the values of the other attributes. I have tested that only one row exists for attribute value == "Credit card" and at least one row exists for the attribute value == "Debit card"



So basically I need to get a hold of the 5 child nodes for each instance of the parent.



I am able to retrieve the 5 instance of parent nodes with the right XPath, but I retrieve the child nodes using the getchild() method, but I get child nodes as 25 (in case if we have 5 parent nodes - 5 * 5) but instead of 5 nodes. Basically, I am unable to get a hold of child nodes (count 5) . Whatever way I use, I always retrieve all child nodes under all parent nodes, instead of a particular parent node.



<Parent1>
<child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1>
<child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2>
<child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3>
<child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>
<child5>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child5>
</Parent1>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent2>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent3>
<Parent4>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent4>
<Parent5>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent5>









share|improve this question
















I have the below structure where parent nodes are repeating nodes - lets say 5 nodes. Within these 5 parent nodes, I have 5 repeating child nodes with 5 attributes. I need to retrieve the values of attributes depending upon the value of the attribute.



Lets say one of the attribute values is "Credit card" for one of the rows and for the other 4 rows value of the attribute value is "Debit card". When the value == "Credit card", I need to take the values of the other attributes. I have tested that only one row exists for attribute value == "Credit card" and at least one row exists for the attribute value == "Debit card"



So basically I need to get a hold of the 5 child nodes for each instance of the parent.



I am able to retrieve the 5 instance of parent nodes with the right XPath, but I retrieve the child nodes using the getchild() method, but I get child nodes as 25 (in case if we have 5 parent nodes - 5 * 5) but instead of 5 nodes. Basically, I am unable to get a hold of child nodes (count 5) . Whatever way I use, I always retrieve all child nodes under all parent nodes, instead of a particular parent node.



<Parent1>
<child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1>
<child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2>
<child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3>
<child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>
<child5>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child5>
</Parent1>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent2>
<Parent2>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent3>
<Parent4>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent4>
<Parent5>
<child1>
<child2>
<child3>
<child4>
<child5>
</Parent5>






java xpath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 4:05









Mihai Chelaru

2,357101323




2,357101323










asked Nov 23 '18 at 2:31









aditya mandlekaraditya mandlekar

1




1













  • Kindly suggest how can we handle xpath using java. I wish to avoid using xmlapth as I have already done 99% of my code using xpath . I wish to avoid to switching to xmlpath .I would be thankful for solution towards this issue.

    – aditya mandlekar
    Nov 23 '18 at 2:36











  • XML structure incase its not posted incorrectly above:<Parent1> <child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1> <child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2> <child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3> <child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>

    – aditya mandlekar
    Nov 23 '18 at 2:40





















  • Kindly suggest how can we handle xpath using java. I wish to avoid using xmlapth as I have already done 99% of my code using xpath . I wish to avoid to switching to xmlpath .I would be thankful for solution towards this issue.

    – aditya mandlekar
    Nov 23 '18 at 2:36











  • XML structure incase its not posted incorrectly above:<Parent1> <child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1> <child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2> <child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3> <child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>

    – aditya mandlekar
    Nov 23 '18 at 2:40



















Kindly suggest how can we handle xpath using java. I wish to avoid using xmlapth as I have already done 99% of my code using xpath . I wish to avoid to switching to xmlpath .I would be thankful for solution towards this issue.

– aditya mandlekar
Nov 23 '18 at 2:36





Kindly suggest how can we handle xpath using java. I wish to avoid using xmlapth as I have already done 99% of my code using xpath . I wish to avoid to switching to xmlpath .I would be thankful for solution towards this issue.

– aditya mandlekar
Nov 23 '18 at 2:36













XML structure incase its not posted incorrectly above:<Parent1> <child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1> <child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2> <child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3> <child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>

– aditya mandlekar
Nov 23 '18 at 2:40







XML structure incase its not posted incorrectly above:<Parent1> <child1>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child1> <child2>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child2> <child3>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child3> <child4>"Attribute-1"=Value "Attribute-2"=Value2 "Attribute-3"="Value3" "Attribute-4"=Value2 "Attribute-5"=Value2</child4>

– aditya mandlekar
Nov 23 '18 at 2:40














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439988%2fissues-retrieving-repeated-child-nodes-using-xpath-using-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439988%2fissues-retrieving-repeated-child-nodes-using-xpath-using-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]