473,605 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching node in XmlNode[] in c#

10 New Member
I have an array of XmlNode[] which is returned after deserializing xml document. I have to search particlular XmlNode in the array based on the attribute "instrument " of Record XmlNode.

Sample node lookes like this
Expand|Select|Wrap|Line Numbers
  1. <Record instrument="VOD-US,USD,NORM,R">
  2.   <Field name="variant" type="2">R</Field> 
  3.   <Field name="hi" type="5">19.28</Field>   
  4. </Record>
  5.  
any help will be appreciated.

Regards,
Nags
Nov 10 '08 #1
5 8374
Dormilich
8,658 Recognized Expert Moderator Expert
XmlNode seems to be part of the implementation of DOM in C# (of which I don't know anything), so you could be able to use DOM methods to check the attribute.

sorry I can't be of more help

regards
Nov 10 '08 #2
jkmyoung
2,057 Recognized Expert Top Contributor
Use an iterator for the nodelist, something like:
Expand|Select|Wrap|Line Numbers
  1. foreach XmlNode node in the xmlNode[] {
  2.   XmlNode attr = node.Attributes.getNamedItem("instrument");
  3.   if (attr != null && attr.Value.Equals("VOD-US,USD,NORM,R")) 
  4.     do something
  5. } // end foreach
XMLNodeXmlNode Members (System.Xml)

XMLAttributeCol lectionXmlAttributeCol lection Members (System.Xml)
Nov 10 '08 #3
coolnags
10 New Member
As of now I am doing in the same way as you specified. Here suppose I have 100 nodes I have to parse all the 100 nodes to get the last node. I was looking for something like we have predicate delegate.
Ex: Array.Find()

Is it possilbe in XmlArray[]

Nags
Nov 12 '08 #4
jkmyoung
2,057 Recognized Expert Top Contributor
It would be possible if the attribute was a direct property of the xmlNode. Since the attribute node is contained within each of the XMLNode lists, I don't know of a better way to search through the list. How are you getting this XMLNode []array, (or XMLNodeList?)

If you can, Change the way the list is formed to get the attribute nodes instead of the element nodes. Then when you find the right attribute node, just go to its parent to get the Record node.
Nov 12 '08 #5
raghukv
1 New Member
XPath is query langueage for XML. Using this we can query xml file
Please search net for usage of XPath.

In your case following is the XPath query which serves your purpose.
/Record[@instrument='VO D-US,USD,NORM,R']



@coolnags
Jan 19 '09 #6

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

Similar topics

1
2586
by: Rafaela K. Azinhal | last post by:
Please, help me with following code snippet ' Load xml document Dim xmlDoc As New XmlDocument() xmlDoc.Load(http://localhost/VT/reports/VT_actual_owsPivotTable.xml) ' define namespacemanager Dim xmlNs As New XmlNamespaceManager(xmlDoc.NameTable) Dim nsUri As String = xmlDoc.DocumentElement.GetNamespaceOfPrefix("x") xmlNs.AddNamespace("x", nsUri) ' create template node
2
55563
by: Eirik M. | last post by:
Hi, I've got the following piece of code that's causing me a bit of a problem XmlDocument doc = new XmlDocument (); XmlNode rootNode = doc.CreateNode (XmlNodeType.Element, "usersettings", null); User user = new User (userid); XmlNode rolesNode = user.GetRoles (); rootNode.AppendChild (rolesNode);
4
12390
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't work: Dim oElem as XmlElement
3
3434
by: melanieab | last post by:
Hi, I can't seem to get the syntax correct. I have an xmlnodelist full of elements called "file". Each file has an attribute called "ID". If I just want to get, say, the ID of the second file in the list, how do I write this? Thanks!!! Mel
14
11495
by: neerajb | last post by:
Hi, I am having an XML document(input.xml) which is showing the menu heirarchy used in my application.My requirement is to add "submenu" tag to those menuitems who are having the child menuitems as shown in output.xml. I am using VB.NET framework 1.1. Please Help, i have already invested my 2 days but unable to build the logic as input xml may be having any level of nesting of menuitems.
0
1699
by: RJN | last post by:
Hi I have to read an xml and add the node elements into a hashtable with nodename as key and nodetext as value. If the selected node has childnodes, then value should go as an array. for eg., <Root> <mysection>
1
2885
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The app.config file is listed below and the code is listed below that, the line with "-->>" is where i try to get the node. Can anyone see where I'm going wrong. A dump of the xmlDocument is listed below the code. Note: "MyKey" is set to "Reports"
3
2123
by: Prashant Mahajan | last post by:
Hi All, I am facing a problem regarding accessing the item list of an XML node in IE. While using the following code: for(test in XMLNode) {} I received this XML Node from AJAX's responseXML. This fetches item list in Mozilla and Opera, however it creates errors in IE.
5
7814
WebDunce
by: WebDunce | last post by:
Hi guys, I am trying to develop a simple xml editor. I have an object that has a TreeView. I use the TreeView to display the Xml node info. That's all fine, but i want the user to be able to move the actual xml nodes about by interacting with the non-xml TreeView nodes. my basic algorithm is as follows: user has selected a treeview node if user presses Ctrl+Up Arrow, then
0
8004
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7934
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
8418
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
8071
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
8288
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...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
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
3912
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
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.