Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
how to access the title tag which is inside subcategory tag

sample.xml file

XML
<?xml version="1.0" encoding="UTF-8"?>
<rss>
<item>
    <id>1</id>
    <title>Guidliness</title>
    <desc>On the Internet usually the resume are send via e-mail to respective companies, but it is still important that you carry a copy along with you during your preliminary interview.</desc>
</item>
<item>
    <id>2</id>
    <title>Why do you Need a Resume?</title>
    <desc>A summary of your objectives,educational qualification,experience,skills relevant to the field of work you are going to enter.</desc>
</item>
<item>
    <id>3</id>
    <title>Basics of Writing a Resume</title>
                <subcategory>
                        <title>Basic Standards</title>
                        <desc>Resume is what an employer looks at much before meeting you,it is the first interface you have with your employer.</desc>
               </subcategory>
               <subcategory>
                       <title>Stick of the Point</title>
                       <desc>Employers have a busy schedule, so don't expect them to read through a long resume.</desc>
               </subcategory>
               <subcategory>
                   <title>Words Count</title>
                   <desc>Use of language is extremely important; you need to sell yourself to an employer quickly and efficiently.</desc>
               </subcategory>
               <subcategory>
                   <title>Make the Most of your Experience</title>
                   <desc>Employers need to know what you have accomplished to have an idea of what you can do for them. Don't be vague.</desc>
               </subcategory>
               <subcategory>
                   <title>Honesty is a Good Policy</title>
                   <desc>Employers will feel more comfortable hiring you if they can verify your accomplishments.</desc>
               </subcategory>
               <subcategory>
                   <title>Double-Check for Mistakes</title>
                   <desc>Check your resume for correct grammar and spelling - evidence of good communication skills and attention to detail.</desc>
               </subcategory>
</item>
<item>
    <id>4</id>
    <title>15 Golden Steps</title>
    <desc>The thought of writing a resume scares almost anyone. It's difficult to know where to start or what to include.</desc>
</item>
<item>
    <id>5</id>
    <title>8 Red Flags</title>
    <desc>A Resume is your mirror reflection to a recruiter or prospective employer.</desc>
</item>

</rss>


SampleActivity.Java file in Android
Java
public class AndroidXMLParsingActivity extends ListActivity {

	// All static variables
	static final String URL = "http://10.0.2.2:8080/sample/xmlfiles/sample.xml";
	// XML node keys
	static final String RSS_ITEM = "item"; // parent node
	static final String RSS_ID = "id";
	static final String RSS_NAME = "title";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ArrayList<hashmap><string,>> menuItems = new ArrayList<hashmap><string,>>();

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

		NodeList nl = doc.getElementsByTagName(RSS_ITEM);
		// looping through all item nodes <item>
		for (int i = 0; i < nl.getLength(); i++)
		{
			// creating new HashMap
			HashMap<string,> map = new HashMap<string,>();
			
			Element e = (Element) nl.item(i);
			// adding each child node to HashMap RSS => value
			map.put(RSS_ID, parser.getValue(e, RSS_ID));
			map.put(RSS_NAME, parser.getValue(e, RSS_NAME));
			
			// adding HashList to ArrayList
			menuItems.add(map);
		}

		// Adding menuItems to ListView
		ListAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.flist_item,new String[] { RSS_NAME }, new int[] 
		{
			R.id.name 
		});

		setListAdapter(adapter);

		// selecting single ListView item
		ListView lv = getListView();

		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView			{ 
				// getting values from selected ListItem
				String name = ((TextView) view.findViewById(R.id.name)).getText().toString();				 
				// Starting new intent
				Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
				in.putExtra(RSS_NAME, name);
				Log.d("name", name);				 
				startActivity(in);
			}
		});
	}
}</item></hashmap></hashmap>
Posted
Updated 16-Jul-13 4:32am
v7
Comments
Member 10678436 20-Mar-14 6:07am    
hello, i want my phonebook contact in .xml file in my sdcard android.
Member 11410363 31-Jan-15 5:47am    
How to get data into 3 tree level ExpandableListView from http XML file -Android example code using Domparser....
please...help me...any one

1 solution

check this link
listview-in-android[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900