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

From Progzoo
Jump to: navigation, search
(New page: {{DOM Tutorial}} <div style='width:70ex;float:right;margin:2ex;'>The file http://progzoo.net/world.xml is as shown: <pre style="border-style:solid;border-width:thin;"> <world> &l...)
 
(GetElementById)
Line 31: Line 31:
 
       XmlDocument doc = new XmlDocument();
 
       XmlDocument doc = new XmlDocument();
 
       doc.Load("bbc.xml");
 
       doc.Load("bbc.xml");
       XmlElement e = doc.GetElementById("uk");
+
       XmlNodeList nl = doc.GetElementsByTagName("region");
      Console.WriteLine(e.GetAttribute("id"));
+
 
     }catch (Exception e){
 
     }catch (Exception e){
 
       Console.WriteLine(e.ToString());
 
       Console.WriteLine(e.ToString());

Revision as of 21:17, 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

GetElementById

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]