How to parse text and image from xml file in android application?

Q. my sample xml file,
<laptop>
<name>Dell</name>
<image>url image</image>
</laptop>
how to append these data in android application.
In android layout,
TextView txt = (TextView) findViewById(R.id.txtView);
ImageView img = (ImageView) findViewById(R.id.imgView);

Please give sample code...

A. Follow this link : http://stackoverflow.com/questions/12855391/parsing-xml-file-using-java-for-android-based-application

Tutorials for Android programming?
Q. I have searched youtube and I have found three people. TheNewBoston has only 3 tutorials, a person called Edu is not very clear and there is someone else who is pretty good, however I haven't found anything that teaches development for Android applications well. Text or video will do. I have also checked the official tutorials however they're not well set out. Thanks!

A. Basic4android, a simple development environment for developers of Google Android-based apps, is offering Tutorials for Android programming.

Basic4android has a rich set of libraries that make it easy to develop advanced applications. This includes: SQL databases, GPS, Serial ports (Bluetooth), Camera, XML parsing, Web services (HTTP), Services (background tasks), JSON, Animations, Network (TCP/IP), Text To Speech (TTS), Voice Recognition, WebView, AdMob (ads), Charts, Graphics and more.

Need help with displaying local xml file in android?
Q. I have a local xml file in my android app. I am trying to read it. How can I read the id and the description for the book.Here is the xml for it

<?xml version="1.0" encoding="utf-8" ?>
<Books>
<Book id = "1">
<Description>This book is about cooking</Descriptiion>
</Book>
</Books>

A. 1) ewapeeks@yahoo.com:G8AatGO0Ldone
2) sumikoantonaccio@yahoo.com:r47bxncqE7
3) marthanorway@yahoo.com
jr1khv3eS2tdone
4)


---------
darrelloveyceyakovub


try {

File fXmlFile = new File("c:\\file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();

System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("staff");
System.out.println("-----------------------");

for (int temp = 0; temp < nList.getLength(); temp++) {

Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {

Element eElement = (Element) nNode;

System.out.println("First Name : " + getTagValue("firstname",eElement));
System.out.println("Last Name : " + getTagValue("lastname",eElement));
System.out.println("Nick Name : " + getTagValue("nickname",eElement));
System.out.println("Salary : " + getTagValue("salary",eElement));

}
}
} catch (Exception e) {
e.printStackTrace();
}




Powered by Yahoo! Answers

No comments:

Post a Comment