一、读取xml文档
直接读取xml是包含注释内容的,一般需求是读取不包含注释的内容,就需要借助xmlReader进行过滤。
/// <summary> /// 自动获取菜单数量(去掉注释子项) /// </summary> /// <param name="xmlFullPath"></param> /// <returns></returns> private int NumToolsItems(string xmlFullPath) { int num = 0; try { XmlReaderSettings xmlRdSet = new XmlReaderSettings(); xmlRdSet.IgnoreComments = true; XmlReader xmlRd = XmlReader.Create(xmlFullPath, xmlRdSet); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlRd);//xmlFullPath num = xmlDoc.LastChild.ChildNodes.Count; } catch (Exception e) { _logger.ErrorFormat("自动获取菜单数量出错:{0}", e.Message); } return num; } /// <summary> /// 自动获取菜单数量(包含注释子项 最后节点下) /// </summary> /// <param name="xmlFullPath"></param> /// <returns></returns> private int NumToolsItems_All(string xmlFullPath) { int num = 0; try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFullPath);// num = xmlDoc.LastChild.ChildNodes.Count; } catch (Exception e) { _logger.ErrorFormat("自动获取菜单数量出错:{0}", e.Message); } return num; }
二、
http://www.cnblogs.com/shenchao/p/4558944.html