473,609 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to display parent node attribute name in xmlDocument

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

my xml is:

Expand|Select|Wrap|Line Numbers
  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>
  16.  
and the method is:
Expand|Select|Wrap|Line Numbers
  1.  private void btnGetNum_Click(object sender, EventArgs e)
  2. {
  3.  XmlNodeList towns = doc.GetElementsByTagName("town");
  4.    foreach (XmlNode town in towns)
  5.    {
  6.       if (txtInput.Text.Equals(town.ChildNodes[0].Value))
  7.       {
  8.        lstResult.Items.Add("area code is" +  ??????????);
  9.    }
  10. }
  11.  
</phonebook>
Feb 17 '11 #1
2 4404
GaryTexmo
1,501 Recognized Expert Top Contributor
An XmlNode object has a parent node. You should be able to get the parent node of the town, then parse the attributes present in the XmlAttributes property.

Give that a try and let me know how it works out :)
Feb 17 '11 #2
tookerello
5 New Member
the solution is to use town.ParentNode .Attributes["code"].Value
Feb 18 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2621
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML: **************************************************************
2
14879
by: john smith | last post by:
Hello, I am having trouble getting the parent node of an xml document using xslt. I am trying to return the node wine, but this does not return wine but the element values under wine. I thouht this would work. I am looking for the prices context and then ask for the parent node right? What am I doing wrong? Thanks in advance for your help.
2
1396
by: David Lei | last post by:
Hi, How do I add a new parent node to the existing nodes? I have an existing XmlDocument object like this: <item> <something>ABC</something> <item> <item> <something>DEF</something>
5
9551
by: Paw Pedersen | last post by:
When you are "working" on a specific node from a XmlDocument instance, is it possible to get the full xpath to this node? Regards Paw
0
1190
by: ajchan16 | last post by:
Hi, I have an issue that I just cannot figure out. I currently have an XML file that I would like to populate into a datagrid on my windows application. Now I know how to use the DataView to filter out all the rows I need, but unfortunately this does not work if the value I need to use to filter is in the parent node. Can someone help me figure out how to basically filter from a value of the parent node (Customer name attribute) then...
0
1223
by: krina | last post by:
I am new in this field and have just started learning XML and xslt, Now I am having a XML file.......having structure as follows..... <?xml version="1.0" encoding="UTF-8"?> <page> <item xPos="20" yPos="10" layer="1">This is at layer one <item xPos="30" yPos="10" layer="1">This is 1st child of item one</item>
4
6486
by: MA | last post by:
Hi, How to access the total number of child nodes from a parent node. For example, I would like to get the total number of child nodes from <parent1and <parent2node. The SelectNodes method return the total number of <foldernodes (9) regardless of calling from the <parent1> and <parent2node. XML: ----------------------------------
3
5446
by: Irocivan | last post by:
Hello, I download a nice collapse menu for free distribution from the internet. It works very well except that none of the parents nodes are clickable (i.e. when clicking on the parent node, the link does not work). For example, if the below content is included in the html page, I would like that page www.fruit.com can be loaded whenever I click it. However the javascript does not allow the page to be loaded, It would only work for the child...
2
1878
by: npm | last post by:
I'm trying to display XML nodes whose parent node has a certain attribute (or attribute value). I have one code that works in Firefox, but not IE and another code that works in IE, but not Firefox. This one works in FF, but not IE: <script type="text/javascript"> xmlDoc=loadXMLDoc("sampleFileZ.xml"); x=xmlDoc.getElementsByTagName("sampleNode"); for (i=0;i<x.length;i++) { if (x.parentNode.hasAttribute("sampleAtt"))
1
3669
by: SWETA123 | last post by:
I will very helpful to you if you can help me out in my below problem. I am not getting idea what should be the right approach for this. Here is my problem. I have below (sample)xml. <Rules> <MapRule input="@PARENT()" output="Sales_Totals" /> <MapRule input="''" output="Sales_Totals@name" /> <MapRule input="''" output="Sales_Totals@type" /> <MapRule input="" output="Sales_Totals@allTimeSales" />
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.