using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Xml;
using System.IO;
using System.Reflection;

namespace FileManager
{
    public class XmlManager
    {
        #region 创建Xml文件，并创建根节点和属性
        /// <summary>
        /// 创建Xml文件，并创建根节点和属性
        /// </summary>
        /// <param name="xmlfullname">Xml文件的全路径</param>
        /// <param name="rootnode">根节点名</param>
        /// <param name="list_attributes">根节点的属性键值对</param>
        /// <returns></returns>
        public static Boolean CreateXmlFile(String xmlfullname)
        {
            XmlDocument xmlDoc = new XmlDocument();
            //创建类型声明节点  
            XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "");
            xmlDoc.AppendChild(node);
            //创建根节点  
            XmlNode root = xmlDoc.CreateElement("XMLData");
            xmlDoc.AppendChild(root);
            try
            {
                xmlDoc.Save(xmlfullname);
                return true;
            }
            catch (Exception e)
            {
                //显示错误信息  
                Console.WriteLine(e.Message);
                return false;
            }
        }
        #endregion

        #region 获取Xml文件中节点内的信息
        /// <summary>
        /// 获取Xml文件中节点内的信息
        /// </summary>
        /// <param name="xmlfullname">Xml文件的全路径</param>
        /// <returns></returns>
        public static XmlNodeList GetXmlMeasureFlowNodeInfo(String xmlfullname)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                //加载XML文件  
                xmlDoc.Load(xmlfullname);
                //获得文档中的根节点。
                XmlElement xmlElement = xmlDoc.DocumentElement;
                XmlNodeList nodeList = xmlElement.ChildNodes;
                XmlNodeList nodeChildList = null;
                foreach (XmlNode item in nodeList)
                {
                    //获取当前节点下的所有信息
                    nodeChildList = item.ChildNodes;
                    break;
                }
                return nodeChildList;
            }
            catch (Exception ex)
            {
                LogManager.LogError(ex.ToString());
                return null;
            }
        }
        #endregion
    }
}
