I need to create an XPath expression that does the following:
This XPath expression returns NodeB if it exists (and has text content) and NodeA in the other case:
//my:NodeB[text()] | //my:NodeA[text() and not(//my:NodeB[text()])]
If you want to get all sub-elements you can append /*
after the selected node, like this
//my:NodeB[text()]/* | //my:NodeA[text() and not(//my:NodeB[text()])]/*