0

My xml is like this:

<string-array name="persons_array">
        <item deptcode="11S01">person 1</item>
        <item deptcode="12S01">person 2</item>
        <item deptcode="20S01">person 3</item>
        <item deptcode="35S04">person N</item>
    </string-array>

All I need is to get the deptcode and put it in an editbox.

Ty

Liou
  • 35
  • 3

1 Answers1

0

try this:

DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource source = new InputSource();
source.setCharacterStream(new StringReader(xmlRecords));
Document doc = db.parse(source);
NodeList nodes = doc.getElementsByTagName("item");
for(int i = 0; i< nodes.getLength();i++)
{               
   NamedNodeMap attr = nodes.item(i).getAttributes();
//Next string is your deptcode 
   String str = attr.getNamedItem("deptcode").getNodeValue();
   //Here you can set it to EditText
}
Vladimir
  • 3,774
  • 3
  • 23
  • 27
  • Thanks for your answer. I'm absolute beginer. I guess before starting developing in android I'll have to make one step back and learn some java! – Liou Nov 30 '11 at 22:20