How to write a single LINQ to XML query to iterate through all the child elements & all the attributes of the child elements?

前端 未结 1 1054
耶瑟儿~
耶瑟儿~ 2021-01-16 03:16

I am developing asp.net mobile application. I am using XML as a database. I am querying on the XML to access the required elements & attributes by using LINQ to XML in .

相关标签:
1条回答
  • 2021-01-16 03:34

    You could just iterate through all the elements and retrieve the attributes for each:

    var allDescendants = myElement.DescendantsAndSelf();
    var allDescendantsWithAttributes = allDescendants.SelectMany(elem =>
        new[] { elem }.Concat(elem.Attributes().Cast<XContainer>()));
    
    foreach (XContainer elementOrAttribute in allDescendantsWithAttributes)
    {
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题