Linq to Xml

.Net中的System.Xml.Linq命名空间提供了linq to xml的支持

例子xml file

<note>
 
    <to>Tove</to>
 
    <from>Jani</from>
 
    <heading>Reminder</heading>
 
    <body>Don't forget me this weekend!</body>
    <user id="1">
    
        <name>aking</name>
        <sex>man</sex>
        <age>27</age>
    </user>
    <user id="2">
        <name>jambor</name>
        <sex>man</sex>
        <age>27</age>
    </user>
</note>

how to operate

 var query = from c in xml.Descendants("user")
                        let a = c.Element("name").Value
                        where a == "aking"
                         select new { c, a };
原文地址:https://www.cnblogs.com/akingyao/p/3141882.html