Hi,
I'm new on developing android apps and i have a code which does the xml
parsing but i have some issues.
The code reads the xml that is hosted on a web server but when it displays
to my app, i can't see all xml file.
Can you help trying to make this code scrollable?
(sorry my bad english)
The code is:
public class XMLParsingDOMExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Create a new layout to display the view */
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);
/** Create a new textview array to display the results */
TextView name[];
TextView website[];
TextView category[];
TextView dia[];
TextView abb[];
try {
URL url = new URL("http://www.carlosboto.com/ualg/menu.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("item");
/** Assign textview array lenght by arraylist size */
name = new TextView[nodeList.getLength()];
website = new TextView[nodeList.getLength()];
category = new TextView[nodeList.getLength()];
dia = new TextView[nodeList.getLength()];
abb = new TextView[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
name[i] = new TextView(this);
website[i] = new TextView(this);
category[i] = new TextView(this);
dia[i] = new TextView(this);
abb[i] = new TextView(this);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("almoco");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
name[i].setText("Almoco = "
+ ((Node) nameList.item(0)).getNodeValue());
NodeList websiteList = fstElmnt.getElementsByTagName("jantar");
Element websiteElement = (Element) websiteList.item(0);
websiteList = websiteElement.getChildNodes();
website[i].setText("Jantar = "
+ ((Node) websiteList.item(0)).getNodeValue());
NodeList categoryList = fstElmnt.getElementsByTagName("sobremesa");
Element categoryElement = (Element) categoryList.item(0);
categoryList = categoryElement.getChildNodes();
category[i].setText("Sobremesa = "
+ ((Node) categoryList.item(0)).getNodeValue());
NodeList diaList = fstElmnt.getElementsByTagName("dia");
Element diaElement = (Element) diaList.item(0);
diaList = diaElement.getChildNodes();
dia[i].setText("Dia = "
+ ((Node) diaList.item(0)).getNodeValue());
NodeList abbList = fstElmnt.getElementsByTagName("abb");
Element abbElement = (Element) abbList.item(0);
abbList = abbElement.getChildNodes();
abb[i].setText(""
+ ((Node) abbList.item(0)).getNodeValue());
//category[i].setText("Sobremesa = "
// + categoryElement.getAttribute("sobremesa"));
layout.addView(abb[i]);
layout.addView(dia[i]);
layout.addView(name[i]);
layout.addView(website[i]);
layout.addView(category[i]);
}
} catch (Exception e) {
System.out.println("XML Pasing Exception = " + e);
}
/** Set the layout view to display */
setContentView(layout);
}
}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/877f3245-d4c0-4396-aee1-0d122e4f4ffc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.