473,547 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Xmlnode by an attribute

Hi,

Im trying to get a xmlnode having the value of an attribute, but without
success

this is my xml file:
<promotions>
<promotion id="0">
<image>images/gifs/Panel4/Panel4_Prom2.gi f</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="1">
<image>images/gifs/Panel4/Panel4_Prom2.gi f</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="2">
<image>images/gifs/Panel4/Panel4_Prom2.gi f</image>
<text>Text of promotión 1</text>
</promotion>
<promotioninuse >1</promotioninuse>
</promotions>

First i take the Promotion to use from the node <promotioninuse > like this
(until here no problem):
XmlNode PromotioninUse= RootNode.Select SingleNode("pro motioninuse");
string id=PromotioninU se.InnerText;

My problem comes where i try to get the node that have an attribute with the
value in this case "1" (promotion in use)

but this code doesnt work:

XmlNode PromotionData=R ootNode.SelectS ingleNode("prom otion[id]");

How could i get the correct promotion...
--
Thanks
Regards.
Josema
Nov 16 '05 #1
2 13967

try this:
XmlNode PromotionData=R ootNode.SelectS ingleNode("prom otion[@id='1']");

"Josema" <Je******@ocu.o rg> wrote in message
news:A3******** *************** ***********@mic rosoft.com...
Hi,

Im trying to get a xmlnode having the value of an attribute, but without
success

this is my xml file:
<promotions>
<promotion id="0">
<image>images/gifs/Panel4/Panel4_Prom2.gi f</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="1">
<image>images/gifs/Panel4/Panel4_Prom2.gi f</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="2">
<image>images/gifs/Panel4/Panel4_Prom2.gi f</image>
<text>Text of promotión 1</text>
</promotion>
<promotioninuse >1</promotioninuse>
</promotions>

First i take the Promotion to use from the node <promotioninuse > like this
(until here no problem):
XmlNode PromotioninUse= RootNode.Select SingleNode("pro motioninuse");
string id=PromotioninU se.InnerText;

My problem comes where i try to get the node that have an attribute with
the
value in this case "1" (promotion in use)

but this code doesnt work:

XmlNode PromotionData=R ootNode.SelectS ingleNode("prom otion[id]");

How could i get the correct promotion...
--
Thanks
Regards.
Josema

Nov 16 '05 #2
Thanks Dan, it was very useful...
Regards.
Josema.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3575
by: Siu | last post by:
Hi, I've loaded an XmlDocument from a file XML: this file has many similar XmlNode and it is difficult to select them by using SelectSingleNode of the object XmlDocument. I've this question: is it possible to identify each XmlNode of the XmlDocument by using an inner key or something like that ? I precise that I 'm not allowed to change...
2
1483
by: J Mon | last post by:
I have a XML document with elements like <offer> <field name="name"><!]></field> <field name="merchant_id"><!]></field> ..... </offer> I know not the best XML! Now I am selecting different values by XPath having an XmlNode representing the <offer> element. Now when I try something like this
1
4737
by: andrej | last post by:
hi, ich habe eine anwendung, welche ein xml document erstellt. um festzustellen, ob ein element bereits vorhanden ist, verwende ich die funktion selectsinglenode( ....) diese funktion liefert mir ein element des typs node.
1
18144
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it is serialized correctly, and the server returns a response (I've captured the response and it's correct!) but when the .NET deserialize this...
3
27310
by: Andy | last post by:
Hello Guys: What am I doing wrong with this code? I can't seem to get it to simply add an attribute to my node. The node already exists. I am simply opening the XMLDocument and creating one attribute to the document. I am not creating the document new XmlNamespaceManager xnsm = new XmlNamespaceManager(xmlFile.NameTable); ...
0
1192
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
When I create a tree view control from XML document, I use XmlNode.Name in the node list iteration. But sometime, it is supposed that it got the element name. But sometimes it got the element name and first attribute together. For eaxmple, I use the following iteration code after creating the root from DOM.DocumentElement.Name. -----...
5
2687
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler so I can have a custom config section in my config file. The IConfigurationSectionHandler.Create method just returns the 'section' XmlNode back to...
2
4620
by: =?iso-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello! Is it possible to use the object XMLNode as a parameter in an interface function of a WCF service? In my case I get the error message: XmlNode ProcessServiceRequest(XmlNode request); Unable to serialize type "System.Xml.XmlNode". Use the attribute
4
13567
by: CSharper | last post by:
I am reading an XmlFile using XmlDocument and traverse through the XmlNode, as I read I need to append an attribute to the XmlNode on some conditions. I tried xmlNode.Attributes.Append() It takes only XmlAttribute and in this when I create a new XmlAttribute, it doesn't allow me to set the name and value as the name is only the readonly...
0
7507
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...
0
7435
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...
0
7698
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. ...
0
7947
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...
1
7461
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...
1
5361
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...
0
5080
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...
0
3492
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...
1
1922
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.