XML Parsing save all in TextView- in Android

NormLI64

New Member
I want to parse the following XML File:\[code\] <menu><item><team1>deu</team1><team2>por</team2><result>1:0</result></item><item><team1>pol</team1><team2>gre</team2><result>1:1</result></item></menu>\[/code\]I found a Tutorial: http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/But this saves the parsed Data in a ListView. But I want to save it all in a TextView. I want every Item in one TextView with a Linebreak("\n") after each node.I changed some of the code from the Tutorial:AndroidXMLParsingActivity :\[code\]public class AndroidXMLParsingActivity extends ListActivity {// All static variablesstatic final String URL = "see xml above";// XML node keysstatic final String KEY_ITEM = "item"; // parent nodestatic final String KEY_ID = "id";static final String KEY_NAME = "team1";static final String KEY_COST = "team2";static final String KEY_DESC = "result";@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_ITEM); // looping through all item nodes <item> for (int i = 0; i < nl.getLength(); i++) { // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); Element e = (Element) nl.item(i); // adding each child node to HashMap key => value map.put(KEY_ID, parser.getValue(e, KEY_ID)); map.put(KEY_NAME, parser.getValue(e, KEY_NAME)); map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST)); map.put(KEY_DESC, parser.getValue(e, KEY_DESC)); // adding HashList to ArrayList menuItems.add(map); } // Adding menuItems to ListView ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.list_item, new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] { R.id.name, R.id.desciption, R.id.cost }); setListAdapter(adapter); // selecting single ListView item ListView lv = getListView(); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // getting values from selected ListItem String name = ((TextView) view.findViewById(R.id.name)).getText().toString(); String cost = ((TextView) view.findViewById(R.id.cost)).getText().toString(); String description = ((TextView) view.findViewById(R.id.desciption)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(KEY_NAME, name); in.putExtra(KEY_COST, cost); in.putExtra(KEY_DESC, description); startActivity(in); } });}\[/code\]Can somebody say how I could save it in a TextView? I am trying for hours to archivie this. But I always get errors. I dont want to have a ListView. Just TextViews. Thank you very much.EDIT:If somebody has got an other Parser who dows this. Please let me know.thanks.
 
Back
Top