0

hi, im trying to display the attribute name of the parent node once the input matches a town name:

my xml is:

<phonebook> 
  <area code="022"> 
    <town>mallow</town> 
  </area> 
  <area code="023"> 
    <town>bandon</town> 
    <town>bray</town>      
  </area> 
  <area code="024"> 
    <town>youghal</town>     
  </area> 
  <area code="025"> 
    <town>fermoy</town>     
  </area> 
</phonebook>

and the method is:

private void btnGetNum_Click(object sender, EventArgs e) 
{ 
 XmlNodeList towns = doc.GetElementsByTagName("town"); 
   foreach (XmlNode town in towns) 
   { 
      if (txtInput.Text.Equals(town.ChildNodes[0].Value)) 
      { 
       lstResult.Items.Add("area code is" +  ??????????); 
   } 
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by tookerello22
0
town.ParentNode.Attributes.ItemOf["code"].Value

Don't do a lot of work with XML and you might be able to skip the ItemOf and just index off of Attributes.

0
town.ParentNode.Attributes.ItemOf["code"].Value

Don't do a lot of work with XML and you might be able to skip the ItemOf and just index off of Attributes.

that works a treat momerath,

thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.