View Demo
Click here
Introduction
Although there are several methods to parse an XML Document automatically using for example XSL, or by loading it to a Datagrid and many other easy and useful ways, I found that it's also useful sometimes to parse XML document “Manually”, by looping through it.
Looping through the XML document gives you the ability to programmatically add condition clause, and filtering
For example you can add a If…then…end if statement, and do different kind of conditions easily with your everyday programming techniques, using XSL for example, you have to first master this language, also on some conditions you can't depend on XSL to parse your XML document.
Details
We will parse the following XML document on this article
| Hotels.xml |
|
<? xml version="1.0" encoding="ISO-8859-1" ?> < Data > < AvailableInventory > < HotelInventory > < BlockID > 100003501 </ BlockID > < HotelName HotelId =" 101651 "> Marriot </ HotelName > < RoomName RoomTypeID =" 1 "> Single </ RoomName > < RoomRate > 60.0 </ RoomRate > < RoomsAvailable > 10 </ RoomsAvailable > </ HotelInventory > < HotelInventory > < BlockID > 100003502 </ BlockID > < HotelName HotelId =" 101652 "> Hilton </ HotelName > < RoomName RoomTypeID =" 2 "> Double </ RoomName > < RoomRate > 60.0 </ RoomRate > < RoomsAvailable > 10 </ RoomsAvailable > </ HotelInventory > …………………………….. </ AvailableInventory > </ Data >
|
The result after parsing will look like the following
| BlockID |
Hotel Name |
Room Type |
Room Rate |
Rooms Avail. |
| 100003502 |
Mariot |
Double |
60.0 |
10 |
| 100003506 |
Hilton |
Double |
60.0 |
10 |
| 100003510 |
Intercontinental |
Double |
60.0 |
10 |