Can somebody find what is wrong with this code. It always returns empty string no matter whatever XPath I choose
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("chart.xml");
XPath xpath = XPathFactory.newInstance().newXPath();
String str = (String) xpath.evaluate("/row[@id='1']", doc.getDocumentElement(), XPathConstants.STRING);
System.out.println("xml string is"+str);
My chart.xml is
<?xml version="1.0" encoding="iso-8859-1"?>
<chart>
<row id="1">
<Select numofobjects="0" id="1000" index="1">
<Table alias="ConvertDetails" name="ConvertDetails"/>
</Select>
</row>
<row id="2">
<Select numofobjects="0" id="2000" index="2">
<Table alias="ConvertDetails" name="ConvertDetails"/>
</Select>
</row>
</chart>
My expected output is
<Select numofobjects="0" id="1000" index="1">
<Table alias="ConvertDetails" name="ConvertDetails"/>
</Select>