Linq to XML, select all attributes and their values for a given node

前端 未结 4 1258
时光说笑
时光说笑 2021-01-22 13:06

I have an xml mapping file that looks something like this


    
        

        
4条回答
  •  借酒劲吻你
    2021-01-22 13:37

    as I am pushed for time I will use a 2 stage process

    But would be interested to hear if this is possible in one query

    var matchingModelXml = from c in mappings.Descendants("model")
                                   where (string)c.Attribute("name") == "modelY"
                                   select c;
    
    var mappingAttributes = from b in matchingModelXml.Descendants("mapping")
                            where (string)b.Attribute("colour") == "White"
                            select b.Attributes();
    

提交回复
热议问题