C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to display parent node attribute name in xmlDocument Posted by tookerello on 17 Feb 2011 at 7:39 AM
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> 



my 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" +  ??????????); 
   } 
} 


Report
Re: how to display parent node attribute name in xmlDocument Posted by anthrax11 on 24 Feb 2011 at 2:33 PM
Try this:
town.ParentNode.Attributes.GetNamedItem("code").Value



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.