C#:Looping over DOM Tutorial
From Progzoo
DOM Tutorials
Looping over DOM
The file http://progzoo.net/world.xml is as shown:
<world> <region name='Europe'> <country id='de' name='Germany' pop='82000000'/> <country id='fr' name='France' pop='60000000'/> ... </region> <region id='Asia'> <country id='cn' name='China' pop='1300000000'/> ... </region> ... </world>
Contents |
GetElementsByTagName
The program shown uses GetElementsByTagName. It returns a XmlNodeList. The class XmlNodeList includes the Count property.
Change the program so that it prints the number of the country elements.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Searching for large countries
Give the names of the countries with a population of at least 200000000 (200 million).
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Listing regions
For each region show the name and the number of countries in the region.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Casablanca infobox
The file casablanca.xml has a table element where attribute class Contains "infobox".
Show the number of child nodes.
http://xmlzoo.net/casablanca.xml
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Casablanca Starring
- Find the infobox
- Find the th nodes
- Find the th element where the InnerText is "Starring"
- Go to the next sibling
- Find all the <a> elements
- Print the InnerText
Find the list of people "Starring"
http://xmlzoo.net/casablanca.xml
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]