linq xml读取

<?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
          
}

posted @ 2013-07-11 18:06  梨花驿路  阅读(248)  评论(0编辑  收藏  举报