HTML Code:
<catalog> <book> <title>XML Developer's Guide</title> <author>Gambardella, Matthew</author> </book> <book> <title>Midnight Rain</title> <author>Ralls, Kim</author> </book> <book> <title>Hello World</title> <author>Richard, Kim</author> <author>Smith, Joe</author> </book> </catalog>
Code:
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
dFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(xmlbookfile);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//book/title/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
String bname= nodes.item(i).getNodeValue();
if (keyword.equalsIgnoreCase(userinput)){
// i would like to retrieve the author text node
}
