Difference between revisions of "C#:Looping over DOM Tutorial"

From Progzoo
Jump to: navigation, search
(GetElementById)
(GetElementById)
Line 18: Line 18:
 
  NodeList
 
  NodeList
 
<div style='clear:right'></div>
 
<div style='clear:right'></div>
==GetElementById==
+
==GetElementsByTagName==
 
<question lang='cs' className='Demo' copyFile='world.xml'>
 
<question lang='cs' className='Demo' copyFile='world.xml'>
 
The program shown uses GetElementById.
 
The program shown uses GetElementById.
Line 30: Line 30:
 
     try{
 
     try{
 
       XmlDocument doc = new XmlDocument();
 
       XmlDocument doc = new XmlDocument();
       doc.Load("bbc.xml");
+
       doc.Load("world.xml");
 
       XmlNodeList nl = doc.GetElementsByTagName("region");
 
       XmlNodeList nl = doc.GetElementsByTagName("region");
 
     }catch (Exception e){
 
     }catch (Exception e){

Revision as of 21:20, 30 May 2008

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>

This this tutorial we look at the following members of the DOM interface

NodeList

GetElementsByTagName

The program shown uses GetElementById.

Change the program so that it prints the name of the country with id "ca".


[Font] [Default] [Show] [Resize] [History] [Profile]