博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

读取XML文件

Posted on 2013-03-07 09:55  澍可  阅读(137)  评论(0编辑  收藏  举报

1.文件路径

右键xml文件,选择属性,Build Action 选择Content,此时xml文件就在项目根目录下,直接引用xml文件名即可。

2.遍历节点

        private ReadXML()
        {
            XmlDocument doc = new XmlDocument();
            string attribute1= string.Empty;
            string attribute2 = string.Empty;
            string sqlColumnName = string.Empty;

            doc.Load(fileName);
            var tables = doc.SelectNodes(@"/Node1/table");
            foreach (XmlElement table in tables)
            {
                attribute1 = table.Attributes["attributeNameOrIndex"].Value; 
          attribute2
= table.Attributes["attributeNameOrIndex"].Value;
foreach (XmlElement field in table.SelectNodes("column[@scope='all' or @scope='oracle']"))
{
sqlColumnName
= field.Attributes["name"].Value; //result.Add(field.FirstChild.Attributes["displayName"].Value, "");
            //.........
); } } }