XmlResourceParser is empty?

Oreybbry

New Member
I am currently creating a android application and I have a list for the user to select and I want an image for each item at the side. I have created an adapter for the list as well as a separate list_row layout for the list.The actual data for the list is stored locally in res/xml/data.xml and it is as below:\[code\]<dataset> <data> <name>all</name> <image>all</image> </data> <data> <name>car</name> <image>car</image> </data></dataset>\[/code\]Now on the Main Activity for this list I have tried to parse the XML data from the local source and then pass that as a string to a Document element and process the data. I have debugged the issue and notice that the line below is not working as the string being set is empty:\[code\]XmlResourceParser parserXml = getResources().getXml(R.xml.data);String xmlString = parserXml.getText();\[/code\]The full code for parsing the data is below:\[code\] XmlResourceParser parserXml = getResources().getXml(R.xml.dresses); String xmlString = parserXml.getText(); // getting XML from URLXMLParser parser = new XMLParser(); Document doc = parser.getDomElement(xmlString); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_DATA); for (int i = 0; i < nl.getLength(); i++) { HashMap<String, String> map = new HashMap<String, String>(); Element e = (Element) nl.item(i); map.put(KEY_NAME, parser.getValue(e, KEY_NAME)); map.put(KEY_IMAGE, parser.getValue(e, KEY_IMAGE)); dataInfo.add(map); }\[/code\]Can anyone please help me with this, thanks in advance :)
 
Back
Top