Take a particular Attribute value from xml..

Posted by Gopal_nivas under ASP.NET on 3/15/2011 | Points: 10 | Views : 1452 | Status : [Member] | Replies : 1
hi..

i have a xml file.
in that i am having the output like this.
<product>
<OPTIONS NAME="dd" SELECTED_DATA="" SELECTED_LABEL="WELCOME"></OPTIONS>
<OPTIONS NAME="ins"><![CDATA[hello how are u]]></OPTIONS>
</PRODUCT>

HERE I DONT WANT TO CHANGE THE XML . BECAUSE THIS IS MY REQUIREMENT

here i want to take name="ins" value l.e)store the "hello how are u" value to a string variable.

how to do this..

need ur suggestions with example
regards
gopal.s




Responses

Posted by: NDebata on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can use LINQ to find out.
Add
using System.Linq;


XElement xe=XElement.Load(<XML FilePath>);
var ele=xe.Elements().where(a=>a.attribute("name").Value=="ins").FirstOrDefault();
if(ele !=null)
{
string _str=ele.Value;//you will get your value
}


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

Login to post response