Take Node Values From XML C#..

Posted by Gopal_nivas under ASP.NET on 2/8/2011 | Points: 10 | Views : 1959 | Status : [Member] | Replies : 8
hi..

i have the XML information like this..

<PRODUCT PRICE="600" SIZE="3.15' x 2.65'">
<OPTIONS NAME="FINISH" SELECTED_DATA="GOLD" SELECTED_LABEL="GOLD">
<OPTION LABEL="GOLD" />
<OPTION LABEL="YELLOW" />
</OPTIONS>
<OPTIONS NAME="ATTACHMENT" SELECTED_DATA="" SELECTED_LABEL="HELLO">
<OPTION LABEL="HELLO" DATA="" />
<OPTION LABEL="GG" DATA="" />

</OPTIONS>
</PRODUCT>

I WANT TO SELECT THE OPTIONS "SELECTED_LABEL" VALUES
I.E)
THE OUTPUT WILL BE "GOLD" AND "HELLO"

HOW TO GET THESE VALUES..
NEED UR SUGGESTIONS WITH EXAMPLES

REGARDS
GOPAL.S




Responses

Posted by: Naimishforu on: 2/8/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Are you aware of something called as XPATH?? Try using that, let me know if you are not aware of!!

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gopal_nivas on: 2/8/2011 [Member] Starter | Points: 25

Up
0
Down
hi naimi..
thanks for ur response..

plz give me the examples for my scenario..


regards
gopal.s

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naimishforu on: 2/8/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Please check out the below link for the example of your scenario :D

http://www.dotnetfunda.com/codes/code1251-take-node-values-from-xml-csharp.aspx

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naimishforu on: 2/8/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi, Please Mark As Answer if this has resolved your query.

Thanks.

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 2/8/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Dear Gopal,

You can read these articles, that shows many ways to read and write xml values.

http://www.dotnetfunda.com/articles/article425-adding-removing-xml-attribute-from-xml-file-in-net-.aspx
http://www.dotnetfunda.com/articles/article160.aspx

Hope these will help you.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 2/8/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Check the link... it has many links for your requirements...

http://www.c-sharpcorner.com/articles/articlelisting.aspx?sectionid=1&subsectionid=79

Thanks
Karthik
www.f5Debug.net

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naimishforu on: 2/9/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
The exact code for you would be,

 XPathNodeIterator iterator = navigator.Select("/PRODUCT/OPTIONS/@SELECTED_LABEL");


Thanks

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/10/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
You can use LINQ to xml concepts also to query the required value.

Load the xml data into XDocument object and query as

var selectedlabels = from labels in xDoc.Decendants("OPTIONS")
select new (lbl = labels.Attribute("SELECTED_LABEL").Value);

//then you can loop thru the selected labels to get the result.
foreach(var label in selectedlables)
{
MessageBox.Show(label.lbl.ToString());
}

Regards
Madhu


Thanks and Regards
Madhu

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response