[Android] truy xuat xml tren android

Giả sử có file xml định dạng như sau:
<?xml version=“1.0” encoding=“UTF-8”?>
<countries>
<country>
<ten>VIET NAM</ten>
<decription>Day la viet nam</decription>
</country>

</countries>
.
Màn hình layout gom có 1 edittẽt và 1 buttun. Khi đièn tên nươcs và ấn buttun thì sẽ hiện mô tả từ file xml tuong ung. Làm sao đay?

đọc từng element country, kiểm tra <ten> nếu đúng với tên nước đang cần thì truy xuất nội dung trong description

em phải bắt sự kiện click button và sử dụng Intents để chuyển từ class này sang class khác: startActivity(new Intent(this, Activity2.class)). Em nên tìm đọc cuốn beginning android xuất bản của Wiley Publishing, Inc, trong đó có căn bản của Android.

Cai phan bat su kien em bit, bí cái phần làm thế nào để tìm và truy xuất ra. Bị exception ko ah.

[QUOTE=09520118;196283]đọc từng element country, kiểm tra <ten> nếu đúng với tên nước đang cần thì truy xuất nội dung trong description[/QUOTE]
Cái này mình biết nhưng cách làm mình bí. hehe

InputStream in=getResources().openRawResource(R.xml.mota);

		DocumentBuilder builder=DocumentBuilderFactory
		.newInstance()
		.newDocumentBuilder();
		Document doc=builder.parse(in, null);
		NodeList words=doc.getElementsByTagName("country");

////
dòng cuối cùng ko báo lổi nhưng bị Exception

[QUOTE=09520682;196306]InputStream in=getResources().openRawResource(R.xml.mota);

		DocumentBuilder builder=DocumentBuilderFactory
		.newInstance()
		.newDocumentBuilder();
		Document doc=builder.parse(in, null);
		NodeList words=doc.getElementsByTagName("country");

////
dòng cuối cùng ko báo lổi nhưng bị Exception[/QUOTE]

Bạn thử cái này xem:

                    File xmlFile = new File("mota.xml");
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(xmlFile);
		doc.getDocumentElement().normalize();
		NodeList nList = doc.getElementsByTagName("country");