c# 用dataset读取xml也很方便

来源:互联网 发布:软件生命周期模型 编辑:程序博客网 时间:2024/04/29 14:48
      <?xml version="1.0" encoding="utf-8"?>            <root>             <code>0</code>            <message>Success</message>            <roles>            <role><name>Role1</name><selected>false</selected></role>            <role><name>Role2</name><selected>true</selected></role>            </roles>            </root>            DataSet dt = new DataSet();            dt.ReadXml("tt.xml");            string code=dt.Tables["root"].Rows[0]["code"].ToString();            string message = dt.Tables["root"].Rows[0]["message"].ToString();            string name1 = dt.Tables["role"].Rows[0]["name"].ToString();            string selected1 = dt.Tables["role"].Rows[0]["selected"].ToString();            string name2 = dt.Tables["role"].Rows[1]["name"].ToString();            string selected2 = dt.Tables["role"].Rows[1]["selected"].ToString(); 
      <?xml version="1.0" encoding="utf-8"?>            <encryption>              <info InfoId="1" Password="11" />              <info InfoId="2" Password="22" />              <info InfoId="3" Password="33" />              <info InfoId="4" Password="44" />              <info InfoId="5" Password="55" />              <info InfoId="6" Password="66" />            </encryption>            DataSet dt = new DataSet();            dt.ReadXml("t.xml");            for (int i = 0; i < dt.Tables["info"].Rows.Count; i++)            {                string infoid1 = dt.Tables["info"].Rows[i]["InfoId"].ToString();                string password1 = dt.Tables["info"].Rows[i]["Password"].ToString();                         }


0 0
原创粉丝点击