473,508 Members | 2,255 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.gif</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="1">
<image>images/gifs/Panel4/Panel4_Prom2.gif</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="2">
<image>images/gifs/Panel4/Panel4_Prom2.gif</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.SelectSingleNode("promotio ninuse");
string id=PromotioninUse.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=RootNode.SelectSingleNode("promotion[id]");

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

try this:
XmlNode PromotionData=RootNode.SelectSingleNode("promotion[@id='1']");

"Josema" <Je******@ocu.org> wrote in message
news:A3**********************************@microsof t.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.gif</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="1">
<image>images/gifs/Panel4/Panel4_Prom2.gif</image>
<text>Text of promotión 1</text>
</promotion>
<promotion id="2">
<image>images/gifs/Panel4/Panel4_Prom2.gif</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.SelectSingleNode("promotio ninuse");
string id=PromotioninUse.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=RootNode.SelectSingleNode("promotion[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
3570
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...
2
1480
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...
1
4734
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...
1
18135
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...
3
27304
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...
0
1191
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...
5
2683
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...
2
4618
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);...
4
13559
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...
0
7229
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,...
0
7333
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,...
1
7061
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...
0
7502
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...
0
5637
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,...
0
4716
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...
0
3208
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...
0
1566
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 ...
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.