Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to generalise this code

harishak reddy
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();


XPathExpression expr
= xpath.compile("//Pool[@name='BLR' and @enabled='true']/*/text()");

Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;

System.out.println("pool name BLR and enabled True");

for (int i = 0; i < nodes.getLength(); i++) {

I have many XPathExpression like expr1 ,expr2 etc to read and can i generalise this code? I am new to java.Can any one give a solution
Thank you !
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic