日期:2014-05-17  浏览次数:20492 次

怎么获取xml指定节点的内容
<?xml version="1.0"?><response action="registration"><element><properties name="username">test1</properties><properties name="ticket">Td2p1py1vk10mlk</properties><properties name="status">0</properties><properties name="errdesc"></properties></element></response>

返回来这么一段。怎么获取到。ticket里面的值呀。

------解决方案--------------------
string xml = @"<?xml version=""1.0""?>
<response action=""registration"">
<element>
<properties name=""username"">test1</properties>
<properties name=""ticket"">Td2p1py1vk10mlk</properties>
<properties name=""status"">0</properties>
<properties name=""errdesc""></properties>
</element>
</response>
";
string val = XDocument.Load(new StringReader(xml)).Descendants("properties").Where(c => c.Attribute("name").Value == "ticket").First().Value; ;

这个可以不