davy smith

davy smith

  • NA
  • 7
  • 0

how to display parent node attribute name in xmlDocument

Feb 17 2011 10:01 AM
hi, im trying to display the attribute name of the parent node once the input matches a town name:

my xml is:

  1. <phonebook>
  2.   <area code="022">
  3.     <town>mallow</town>
  4.   </area>
  5.   <area code="023">
  6.     <town>bandon</town>
  7.     <town>bray</town>     
  8.   </area>
  9.   <area code="024">
  10.     <town>youghal</town>    
  11.   </area>
  12.   <area code="025">
  13.     <town>fermoy</town>    
  14.   </area>
  15. </phonebook>

and method is:

 

  1. private void btnGetNum_Click(object sender, EventArgs e)
  2. {
  •  XmlNodeList towns = doc.GetElementsByTagName("town");
  •    foreach (XmlNode town in towns)
  •    {
  •       if (txtInput.Text.Equals(town.ChildNodes[0].Value))
  •       {
  •        lstResult.Items.Add("area code is" +  ??????????);
  •    }
  • }

    Answers (1)