Good day, dear)
There is an idea to create an application (android) to display class schedules with the ability to synchronize with the server. Schedules are stored in an XML file. The essence of the question is the parser, it seems to work correctly, but ideally it receives data in a cycle and displays it in it. I can not think of anything adequate in order to stuff the data into TextView in activity (activity only shows one day of the week and switches over). Here is the parser code:
LinearLayout layout = new LinearLayout(this); layout.setOrientation(1); /** Create a new textview array to display the results */ TextView Item[]; TextView ItemNumber[]; try { URL url = new URL( "http://timetable.esy.es/Timetable.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName("day"); //doc.getElementById("Понедельник"); //NodeList nodeList11 = (NodeList) doc.getElementById("Превая"); NodeList nodeList11 = doc.getElementsByTagName("subj"); /** Assign textview array lenght by arraylist size */ Item = new TextView[nodeList.getLength()]; ItemNumber = new TextView[nodeList.getLength()]; String str = Integer.toString(nodeList11.getLength()); Log.d(LOG_TAG, str); for (int i = 0; i < nodeList11.getLength(); i++) { Node node = nodeList.item(i); Item[i] = new TextView(this); ItemNumber[i] = new TextView(this); Element fstElmnt = (Element) node; NodeList ItemList = fstElmnt.getElementsByTagName("subj"); Element ItemElement = (Element) ItemList.item(0); ItemList = ItemElement.getChildNodes(); Item[i].setText("Subject = " + ((Node) ItemList.item(0)).getNodeValue()); ItemNumber[i].setText("Teacher= " + ItemElement.getAttribute("tech")); layout.addView(Item[i]); layout.addView(ItemNumber[i]); } } catch (Exception e) { System.out.println("XML Pasing Excpetion = " + e); } /** Set the layout view to display */ setContentView(layout);