您的位置:首页 > 编程语言 > C#

c# 用dataset读取xml也很方便

2014-01-14 09:52 447 查看
     <?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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: