xml to datatable

xml:
<DocumentElement>
  <cityconfig>
    <city>阿坝州</city>
    <jc>abazhou</jc>
    <nbf>s</nbf>
    <viewname>view_news_title_index_abazhou</viewname>
  </cityconfig>
  <cityconfig>
    <city>阿克苏</city>
    <jc>akesu</jc>
    <nbf>s</nbf>
    <viewname>view_news_title_index_akesu</viewname>
  </cityconfig>
  <cityconfig>
    <city>安达</city>
    <jc>anda</jc>
    <nbf>n</nbf>
    <viewname>view_news_title_index_anda</viewname>
  </cityconfig>
</DocumentElement>
实现方式:
            string path = "./XMLFile1.xml"; ;
            string content = GetContent(path);
            StringReader txtReader = new StringReader(content);
            XmlTextReader xmlReader = new XmlTextReader(txtReader);
            DataSet ds = new DataSet();
            ds.readxml(xmlReader);
            string m = "";
            foreach (DataColumn c  in ds.Tables[0].Columns)
            {
                m += c.ColumnName + "-";

            }
            return;// ds.Tables[0];
 
调用方法
        public static String GetContent(String vFileName)
        {
            StreamReader reader = new StreamReader(vFileName);
            StringBuilder result = new StringBuilder();
            string line = reader.ReadLine();
            while (line != null)
            {
                result.AppendLine(line);
                line = reader.ReadLine();
            }
            reader.Close();
            return result.ToString();
        }

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念