File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes how to generalise this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to generalise this code" Watch "how to generalise this code" New topic

how to generalise this code

harishak reddy

Joined: Jun 14, 2012
Posts: 1
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 !
I agree. Here's the link:
subject: how to generalise this code
It's not a secret anymore!