Get Xmlnode by an attribute

G

Guest

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("promotioninuse");
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...
 
D

Dan Bass

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top