Download presentation
Presentation is loading. Please wait.
Published byRudolph Stevenson Modified over 9 years ago
1
XML Android Club 2015
2
Agenda XML JSON
3
XML eXtensible Markup Language Used for: data transfer PHP -> Java
4
XML: example
5
Uzbekistan Tashkent Sum
6
XML: practice Add following countries: Russia – Moscow – Ruble China – Beijing – Yuan Japan – Tokyo – Yen US – Washington – US Dollar Germany – Berlin - Euro
7
XML Parsing (разобрать) DOM JDOM StAX JAXB Lynda.com - XML Integration with Java
8
Android XML parsers DOM SAX XmlPullParser
9
DOM: example DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("http://www.w3schools.com/x ml/simple.xml");
10
DOM: example NodeList list = doc.getElementsByTagName("food"); for (int i = 0; i < list.getLength(); i++) { Element element = (Element) list.item(i); String value = element.getElementsByTagName("name").item(0 ).getTextContent(); System.out.println(value); }
11
DOM: practice http://joerichard.net/api/ac/countries.xml Create DocumentBuilderFactory Create DocumentBuilder Create Document -> use before stated URL Get node list Print country names
12
DOM: practice (cont) http://joerichard.net/api/ac/countries.xml Print: [CAPITAL] is capital city of [COUNTRY] Example: Tashkent is capital city of Uzbekistan
13
DOM: practice 2 http://joerichard.net/api/ac/books.xml Create DocumentBuilderFactory Create DocumentBuilder Create Document -> use before stated URL Get node list Print book titles
14
POJO Plain old java object
15
XML - example Belgian Waffles $5.95 Two of our famous Belgian Waffles with plenty of real maple syrup 650
16
POJO - example String name; String price; String description; int calories; Getters + setters
17
XML parsing: example List foodList = new ArrayList<>(); Food food = new Food(); food.setName(name); food.setDescription(description); food.setPrice(price); food.setCalories(Integer.parseInt(calories)); foodList.add(food);
18
POJO - practice http://joerichard.net/api/ac/countries.xml Create list of country POJOs Print amount of countries using POJO list
19
POJO – practice 2 http://joerichard.net/api/ac/books.xml Create list of books POJOs Print amount of books
20
FINAL PRACTICE http://joerichard.net/api/ac/students.xml Create DocumentBuilderFactory Create DocumentBuilder Create Document Create node list Using node list parse XML to POJOs list Print names: firstname+lastname
21
Questions? Do you have questions?
22
Review Chapter 10: File management
23
Next lesson Tic Tac Toe
24
Test: June 29th Warmup-1 & Warmup-2 10%+10% String-1 & String-2 10%+10% Array-1 & Array-2 10%+10% Logic-1 & Logic-2 10%+10% Project Euler 1 problem from 1-20 20% 8*10%+1*20%=100% Next month will be FREE!
25
Thank you Thank you for your attention!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.