开发者

reading an XML string using LINQ

开发者 https://www.devze.com 2023-03-30 17:57 出处:网络
I am calling a sharepoint service /_vti_bin/usergroup.asmx from my silverlight app. In that the method GetAllUserCollectionFromWeb() returns the XML string. I need to iterate th开发者_高级运维rough th

I am calling a sharepoint service /_vti_bin/usergroup.asmx from my silverlight app. In that the method GetAllUserCollectionFromWeb() returns the XML string. I need to iterate th开发者_高级运维rough that XML string to get the required data. But the LINQ to XML in this scenario is not working, as it is working when loading the XML file and getting the req data. How to do the similar functionality of LINQ to SQL with an XML string?

Sample code:

string str = @"<LanguageDetails>
                        <UserNode>
                            <Lang>
                                English
                            </Lang>
                        </UserNode>
                    </LanguageDetails>";

Need to handle the similar string and iterate to read the value using LINQ to XML.


You mean something like this?

string str = @"<LanguageDetails>
                   <UserNode>
                       <Lang>
                           English
                       </Lang>
                   </UserNode>
               </LanguageDetails>";
XElement xLanguageDetails = XElement.Parse(str);
foreach (XElement xUserNode in xLanguageDetails.Elements("UserNode"))
{            
}


In almost all cases where you return no rows when doing LINQ to XML queries, the reason is because there is a namespace in your XML. Check the root nodes to see if there are any namespaces and include them in your LINQ queries.

0

精彩评论

暂无评论...
验证码 换一张
取 消