-2

Possible Duplicate:
How to parse xml using different parent nodes in android

I am making an application in which i have to parse xml data, and i have made that, but i am using only single node in my xml file like, but the thing is now i want to add one more node in my xml file namely, and attributes in both the nodes would be same, and i am using this code, so please let me know what are the changes required to add node in same program, because i want whenever user will click on listview item node row then only data related to should be shown in next activity, and vice-versa :-

// XML node keys
static final String KEY_SONG = "song"; // parent node
static final String KEY_ID = "id";
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "artist";
static final String KEY_DURATION = "duration";
static final String KEY_THUMB_URL = "thumb_url";
3
  • How should we know how your parser looks like? What Kind of parser are you using? Pull - SAX or DOM parser? Commented Oct 8, 2012 at 4:13
  • see this link: androidhive.info/2011/11/android-xml-parsing-tutorial (Similar to this link), but also want to add videos node in xml file Commented Oct 8, 2012 at 4:16
  • i am using dom parser, see this link:-androidhive.info/2012/02/… what are the changes i need to do in java class Commented Oct 8, 2012 at 4:23

1 Answer 1

0

In the xml file add a tag

<video>YOUR CONTENT HERE</video> 

under every

<title>

tag. If you are using the androidhive.com's xml file you will need to download it and then modify it using a program like Notepad++ and the upload it onto a server like the public folder in dropbox, or a FTP server or even local host on your computer.


Changes in JAVA Class

  • Add KEY_VIDEO under the other String Variables (KEY_ARTIST, KEY_TITLE, etc)
  • Add map.put(KEY_VIDEO, parser.getValue(e, KEY_VIDEO));

*If you require it to be displayed in the list view open the lazy adapter and add this:

  • TextView video = (TextView)vi.findViewById(R.id.video); <----- You need to add a text view with this id in the layout (R.layout.listrow)
  • video.setText(song.get(CustomizedListView.KEY_VIDEO));

EDIT

I misunderstood, disregard the above

if you are adding another

<video> 

tag like the

<music> 

tag all you have to do is change this one line.

NodeList nl = doc.getElementsByTagName(KEY_VIDEO);
Sign up to request clarification or add additional context in comments.

12 Comments

what are the changes i need to do in java class, because still i am using these lines of code:- static final String KEY_SONG = "song"; // parent node static final String KEY_ID = "id"; static final String KEY_TITLE = "title"; but i also want to add videos node with similar attributes as in song...
If this is the right answer mark it as correct so that other users with the same problem can find help
thanks to help, useful, but i want to use multiple nodes in a single java class, so how can i write code for all in a java class, i think like this:- // parent node song static final String KEY_SONG = "song"; // parent node videos static final String KEY_SONG = "videos"; static final String KEY_ID = "id"; static final String KEY_TITLE = "title"; and NodeList nl = doc.getElementsByTagName(KEY_SONG);NodeList nl = doc.getElementsByTagName(KEY_VIDEOS); Please let me know am i doing wrong or right, Thanks Again
How are you going to know wether to parse songs or videos?
Probably something like if {CODE HERE TO DETERMINE WHICH ONE TO USE} KEY_NODE = "song" else KEY_NODE = "video"
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.