XML Android Club 2015
Agenda XML JSON
XML eXtensible Markup Language Used for: data transfer PHP -> Java
XML: example
Uzbekistan Tashkent Sum
XML: practice Add following countries: Russia – Moscow – Ruble China – Beijing – Yuan Japan – Tokyo – Yen US – Washington – US Dollar Germany – Berlin - Euro
XML Parsing (разобрать) DOM JDOM StAX JAXB Lynda.com - XML Integration with Java
Android XML parsers DOM SAX XmlPullParser
DOM: example DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(" ml/simple.xml");
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); }
DOM: practice Create DocumentBuilderFactory Create DocumentBuilder Create Document -> use before stated URL Get node list Print country names
DOM: practice (cont) Print: [CAPITAL] is capital city of [COUNTRY] Example: Tashkent is capital city of Uzbekistan
DOM: practice 2 Create DocumentBuilderFactory Create DocumentBuilder Create Document -> use before stated URL Get node list Print book titles
POJO Plain old java object
XML - example Belgian Waffles $5.95 Two of our famous Belgian Waffles with plenty of real maple syrup 650
POJO - example String name; String price; String description; int calories; Getters + setters
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);
POJO - practice Create list of country POJOs Print amount of countries using POJO list
POJO – practice 2 Create list of books POJOs Print amount of books
FINAL PRACTICE Create DocumentBuilderFactory Create DocumentBuilder Create Document Create node list Using node list parse XML to POJOs list Print names: firstname+lastname
Questions? Do you have questions?
Review Chapter 10: File management
Next lesson Tic Tac Toe
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 % 8*10%+1*20%=100% Next month will be FREE!
Thank you Thank you for your attention!