Following is a string containing an XML file that specifies folder structure
String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<folder name=\"c\">" +
"<folder name=\"program files\">" +
"<folder name=\"uninstall information\" />" +
"</folder>" +
"<folder name=\"users\" />" +
"</folder>";
If user enter initial letter of the folder the method must return the folder name (following is part of it method i have tried)
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource src = new InputSource();
src.setCharacterStream(new StringReader(xml));
Document doc = builder.parse(src);
List<String> listObj = new ArrayList<String>();
if(doc.getElementsByTagName("folder").item(0) != null){
System.out.println(doc.getElementsByTagName("folder").item(0).getNodeValue());}
But in my method i always get null. How do I iterate and find out the folder name?