Reputation: 10855
I need to match two elements of either type, how to do it in java with xpath?
For example, I have either
"<?xml version='1.0' encoding='UTF-8'?><A><e1>a</e1></A>"
or "<?xml version='1.0' encoding='UTF-8'?><B><e2>a</e2></B>"
And I need to match either e1
or e2
.
XPathExpression expr = xpath.compile("//e1");
Object result = expr.evaluate(is, XPathConstants.NODESET);//check ((NodeList) result).getLength()
And if it does not match, I need to check similarly for e2
. Is there any simpler and more efficient way, like using a regex?
Upvotes: 0
Views: 88