How to get the attribute value of an item of a string array?

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

Answers


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
}

Need Your Help

Matplotlib - add colorbar to a sequence of line plots

python matplotlib colorbar

I have a sequence of line plots for two variables (x,y) for a number of different values of a variable z. I would normally add the line plots with legends like this:

Java Manifest.mf classpath issues

java variables system classpath manifest.mf

I've been trying to run a jar file - let's call it test.jar - that uses the Sybase jconn3.jar on a Unix system.

Add a common namespace reference by default to all pages in a project

.net visual-studio

Is there any easy way to add a using statement to every class I create in a project without having to write

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.