• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps xmlparsing using hashmap in android

krishnaveni

Well-Known Member
I have to develop one xml parsing example.

Here i have to display category name and artilcle title on belonging category...how can i do ??? please help me....

I have to run the app means am getting the o/p like :

The first 5 article title only dispalyed on all categories..how can i display article title for corresponding category ??? how can i resolve the pbm ??? how can i develop these ??? how can i write the code for these ???? please give me some ideas ???

I have used below code:

[HIGH]
public class MainActivity extends Activity {
static final String URL = "http://webservices/new_feed_articls.xml";
static String KEY_CATEGORY = "Categories";
static final String KEY_TITLE = "Category";
static final String KEY_TITLENAME = "name";
static final String KEY_ARTICLE = "article";
static final String KEY_ARTICLETITLE = "title";
public static ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element

NodeList nl = doc.getElementsByTagName(KEY_TITLE);

// looping through all song nodes &lt;song&gt;
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
//Node nNode = nl.item(i);

HashMap<String, String> map = new HashMap<String, String> ();
Element e = (Element) nl.item(i);
map.put( KEY_TITLE,((Element)nl.item(i)).getAttribute(KEY_TITLENAME));
NodeList nl1 = doc.getElementsByTagName(KEY_ARTICLE);

// looping through all song nodes &lt;song&gt;
for (int j = 0; j < nl1.getLength(); j++) {

map.put( KEY_ARTICLE,((Element)nl1.item(i)).getAttribute(KEY_ARTICLETITLE));
}
songsList.add(map);
}
GridView list = (GridView) findViewById(R.id.listView1);
adapter = new LazyAdapter(this, songsList);
list.setAdapter(adapter);
[/HIGH]
Here i got the all category name well....

But i didnot get the article all title value..here am getting first 5 article titles on all categories...how can i split the article title for beloning category...how can i get the article title value for corresponding category.pls give me solution for these.whats wrong in my code ???
 
Back
Top Bottom