SilverlightShow: Using LINQ to XML in Silverlight Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) RE: Using LINQ to XML in Silverlight 2  so nice http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment4406 ashoka http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Mon, 06 Sep 2010 14:22:08 GMT RE: Using LINQ to XML in Silverlight 2 <span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> <p><Exam></p> <p><Q</p> </span> <p> </p> </span> <p> </p> </span> <p><span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"1</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> ></span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">B</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></</span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">C</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></</span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">D</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></</span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p></Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> <p><Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions name="2"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> <p></Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"></Exam></span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"></span> </p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;">Here how to get the <Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"1</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> ></span>.</span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;">Actually I am bindin this xml to treeview. I am selecting Element "C" on the SelectionChanged Event of treeview. Here I want to get the Ancestors of C. ie <span style="font-family: consolas; font-size: 13px;"><span style="color: #0000ff;"><Q</span><span style="color: #a31515;">uestions </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">="A" ></span><span style="color: #0000ff;">.</span></span> If Use Ancestors mathod then I will get XElement like this</span></p> <span style="font-family: consolas; color: #0000ff; font-size: 13px;"> <p><Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"1</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> ></span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">B</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></</span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">C</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></</span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">D</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></</span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p></Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> <p><Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions name="2"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> <p></Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> <p> </p> <p>But I want like this<span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span> </p> <p><Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"1</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> ></span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="color: #0000ff;"><span style="font-family: consolas; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; font-size: 13px;">B</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; font-size: 13px;">></</span></span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="color: #0000ff;"><span style="font-family: consolas; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; font-size: 13px;">C</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; font-size: 13px;">></</span></span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p><<span style="font-family: consolas; color: #a31515; font-size: 13px;">question</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;"> </span><span style="font-family: consolas; color: #ff0000; font-size: 13px;">name</span><span style="color: #0000ff;"><span style="font-family: consolas; font-size: 13px;">=</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; font-size: 13px;">D</span><span style="font-family: consolas; font-size: 13px;">"</span><span style="font-family: consolas; font-size: 13px;">></</span></span><span style="font-family: consolas; color: #a31515; font-size: 13px;">member</span><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;"><span style="font-family: consolas; color: #0000ff; font-size: 13px;">> <p> </p> <p></Q<span style="font-family: consolas; color: #a31515; font-size: 13px;">uestions</span></p> </span> <p> </p> </span> <p> </p> </span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;">></span></p> </span> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment3710 Rahul http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Thu, 03 Jun 2010 08:06:32 GMT RE: Using LINQ to XML in Silverlight 2 I'm trying to retrieve data from xml into chat controles, but XDocument object not created in my application, I imported Using System.Xml  any  ...... http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment3625 Suresh http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Tue, 18 May 2010 14:40:17 GMT RE: Using LINQ to XML in Silverlight 2 <p>Hi!</p> <p>I'm trying to make a new Object of XDocument but VS tells me that there is not such a class? <br /> Am I to stupid or whats the problem here?</p> <p>regards </p> <p></p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment3002 Zinnsoldat http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Wed, 27 Jan 2010 16:21:52 GMT RE: Using LINQ to XML in Silverlight 2 Ignore previous comments - the problem was here where ((question.Element( "id" )).Equals(CurrentQuestion.ToString())) <p>fixed by</p>  where (((String) question.Element( "id" )).Equals(CurrentQuestion.ToString())) <p>Thanks</p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment2730 test http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Tue, 01 Dec 2009 02:35:03 GMT RE: Using LINQ to XML in Silverlight 2 Hi - I son't know what am I doing wrong!<br /> <p>here is my code - It reads xml file properly but LinQ gives me 0 count</p>         private static IList<Questions> ReadXMLFile(int CurrentQuestion)<br />         {<br />         try<br />             {<br />                 XDocument QuestionXML = XDocument.Load("Question.xml");<br />                 List<Questions> questionList =<br />                     ( from question in QuestionXML.Descendants( "question" )<br />                         where ((question.Element( "id" )).Equals(CurrentQuestion.ToString()))<br />                         select new Questions()<br />                   {<br />                         id= int.Parse(question.Element( "id" ).Value),<br />                         QuestionDesc = question.Element( "questiondescription" ).Value,        <br />                   } ).ToList();<br />                 return questionList;<br />             }<br />             catch (Exception e)<br />             {<br />                 throw e;<br />             }<br />         }    <p>When passing 1 or 2 as currentquestion QuestionList returns 0 count</p> <p> Here is my XML</p> <p> </p> <?xml version="1.0" encoding="utf-8" standalone="yes"?><br />     <questions><br />            <question><br />         <id>1</id><br />                 <questiondescription>First Question</questiondescription><br />        </question><br />        <question><br />         <id>2</id><br />                 <questiondescription>Second Question</questiondescription><br />        </question><br />        </questions> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment2729 test http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Tue, 01 Dec 2009 02:23:45 GMT RE: Using LINQ to XML in Silverlight 2 <p>Am new to silverlight. can anyone help me how to store custom usercontrols's data to XML file. </p> <p>The usercontrols here are basically used for creating flow charts.</p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment2582 shobha http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Wed, 28 Oct 2009 07:29:01 GMT RE: Using LINQ to XML in Silverlight 2 Good. <p>Thanks</p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment1417 Mohammad http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Sat, 04 Apr 2009 17:22:10 GMT RE: Using LINQ to XML in Silverlight 2 <p>Very useful and short blog on working with XML. Thanks for this</p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment1122 Dheeraj http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Thu, 05 Mar 2009 00:59:52 GMT RE: Using LINQ to XML in Silverlight 2 <p>If you want to load the data, read from the XML file, into a DataGrid, take a look at <a href="http://www.silverlightshow.net/items/Introduction-to-the-DataGrid-control-in-Silverlight-2.aspx">this article</a>.</p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment543 Enrai http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Tue, 14 Oct 2008 13:23:19 GMT RE: Using LINQ to XML in Silverlight 2 <p>Hi everyboy!</p> <p>I have done as example but not load data in XML file into datagrid</p> <p> </p> <p>pls, help me!</p> http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx#comment535 ngocthanhtnt@gmail.com http://www.silverlightshow.net/items/Using-LINQ-to-XML-in-Silverlight-2.aspx Fri, 10 Oct 2008 19:57:25 GMT