I'm new at Android and trying to get a local XML file and get data and display it .
Here's my code:
public String GetXmlData()
{
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try
{
builder = builderFactory.newDocumentBuilder();
InputStream is = getAssets().open("words.xml");
Document document = builder.parse(new FileInputStream("C:\\Users\\Ocean\\AndroidStudioProjects\\Deneme1Project\\Deneme1\\build\\res\\assets\\words.xml"));
Element rootElement = document.getDocumentElement();
NodeList nodes = rootElement.getChildNodes();
for(int i=0; i<nodes.getLength(); i++){
Node node = nodes.item(i);
if(node instanceof Element)
{
//a child element to process
Element child = (Element) node;
title = child.getAttribute("title");
String author= child.getAttribute("author");
String year= child.getAttribute("year");
}
}
return title;
}
catch (Exception e)
{
e.printStackTrace();
return e.toString();
}
}
My first question where should I put this XML file? Inside res I created folder and named it assets an put inside it I have rs and r folders :S File not found Exception (File is there :P)