linq xml读取

时间:2023-03-08 20:09:29
<?xml version="1.0" encoding="UTF-8" ?>
<cache>
<chatOld>
<funother>20</funother>
<fun104>200</fun104>
<take>20</take>
</chatOld>
<dog>
<name>Marty</name>
<breed>whippet</breed>
</dog>
<auth name="joey" />
</cache>

获取 funother的值20

XDocumentxml = XDocument.Load(HttpContext.Current.Server.MapPath("~/config/CacheConfig.xml"));

varfirstOrDefault = xml.Elements("cache").Elements("chatOld").Elements("funother").FirstOrDefault();

            if(firstOrDefault != null)

            {

                varintf = firstOrDefault.Value;  //20

           }