Android XML parsing Tutorial

XML is extensible markup language which largely use for android layout and sharing data. XML is one of the popular format to sharing data on the internet while JSON are still not exist. For now is less likely to parsing XML to display content in the mobile application. Why JSON replace XML ? It is because JSON is more light weight , simple and better performance for developer while XML have more duplicate syntax and complex. In this tutorial, I will teach you android xml parsing in the mobile application.

Sample Screen

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “XMLParsingExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add new dependency

Open your build.gradle(Module:app) and add new dependency for parsing the xml.

Create two model class

Right click the package name of your application and add new class name “Recipetypes”. After that, follow the source code below.

Repeat to create a new model class again and this class will be name “Recipetype”. And also copy paste the below sample source code.

Create assets Folder

By creating an assets folder, right click app > new > folder > assets folder. Then you will see one assets folder in your app folder.

Create a new recipetypes.xml file

Right click assets folder and create a new xml file name “recipetypes”. After that, modify the source code to the below sample.

Edit class

Modify your mainactivity class and this class will be parse the xml file and display into your textview.

Run Your Project

Lastly, you can run your application in your mobile device. You will see your textview text change because of xml parsing in the application.

(Android XML Parsing)

Source Code

(Visited 762 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *