i have to develop android xml parsing examples.
Here i have to get the attribute value...
This is code for get the id:
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
here i get the arrtibute value for int:
for (int i = 0; i < nodeList.getLength(); i++) {
Element e = (Element) nodeList.item(i);
Employee employee = new Employee();
employee.setId(Integer.parseInt(e.getAttribute(ATTR_ID)));
ok its done well..
now i have to get the arrtibute value for string...
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
How can i get it ???
pls give me code for these...
Well, there's a number of important pieces of information missing from your question, but assuming that the name field and getter/setter methods reside in the Employee object and that the name attribute exists on the same node as the id attribute, then the following code should work:
for (int i = 0; i < nodeList.getLength(); i++)
{
Element e = (Element) nodeList.item(i);
Employee employee = new Employee();
employee.setId(Integer.parseInt(e.getAttribute(ATTR_ID)));
employee.setName(e.getAttribute(NAME)));
...
}