用SQL語句可以進行處理,希望可以幫得了你!
declare @xml xml
set @xml = '<category name="休闲" CategoryId="2">
<image Id="20">
<date> 2007年5月 </date>
<title> 11 </title>
<desc> 11 </desc>
<thumb> 1111.jpg </thumb>
<img> 1111.jpg </img>
</image>
<image Id="21">
<date> 2007年5月 </date>
<title> 休闲中 </title>
<desc> 休闲中 </desc>
<thumb> 070.jpg </thumb>
<img> 070.jpg </img>
</image>
</category>
<category name="休闲1" CategoryId="3">
<image Id="22">
<date> 2007年5月 </date>
<title> 11 </title>
<desc> 11 </desc>
<thumb> 1111.jpg </thumb>
<img> 1111.jpg </img>
</image>
<image Id="23">
<date> 2007年5月 </date>
<title> 休闲中 </title>
<desc> 休闲中 </desc>
<thumb> 070.jpg </thumb>
<img> 070.jpg </img>
</image>
</category>
<category name="休闲2" CategoryId="4">
<image Id="22">
<date> 2007年5月 </date>
<title> 11 </title>
<desc> 11 </desc>
<thumb> 1111.jpg </thumb>
<img> 1111.jpg </img>
</image>
<image Id="23">
<date> 2007年5月 </date>
<title> 休闲中 </title>
<desc> 休闲中 </desc>
<thumb> 070.jpg </thumb>
<img> 070.jpg </img>
</image>
</category>
';select T.C.value('(@name)[1]','nvarchar(50)') as [name],
T.C.value('(@CategoryId)[1]','nvarchar(50)') as CategoryId
from @xml.nodes('//category') as T(C)
declare @xml xml
set @xml = '<category name="休闲" CategoryId="2">
<image Id="20">
<date> 2007年5月 </date>
<title> 11 </title>
<desc> 11 </desc>
<thumb> 1111.jpg </thumb>
<img> 1111.jpg </img>
</image>
<image Id="21">
<date> 2007年5月 </date>
<title> 休闲中 </title>
<desc> 休闲中 </desc>
<thumb> 070.jpg </thumb>
<img> 070.jpg </img>
</image>
</category>
<category name="休闲1" CategoryId="3">
<image Id="22">
<date> 2007年5月 </date>
<title> 11 </title>
<desc> 11 </desc>
<thumb> 1111.jpg </thumb>
<img> 1111.jpg </img>
</image>
<image Id="23">
<date> 2007年5月 </date>
<title> 休闲中 </title>
<desc> 休闲中 </desc>
<thumb> 070.jpg </thumb>
<img> 070.jpg </img>
</image>
</category>
<category name="休闲2" CategoryId="4">
<image Id="22">
<date> 2007年5月 </date>
<title> 11 </title>
<desc> 11 </desc>
<thumb> 1111.jpg </thumb>
<img> 1111.jpg </img>
</image>
<image Id="23">
<date> 2007年5月 </date>
<title> 休闲中 </title>
<desc> 休闲中 </desc>
<thumb> 070.jpg </thumb>
<img> 070.jpg </img>
</image>
</category>
';select T.C.value('(@name)[1]','nvarchar(50)') as [name],
T.C.value('(@CategoryId)[1]','nvarchar(50)') as CategoryId
from @xml.nodes('//category') as T(C)
解决方案 »
- DataSet数据合并,不用循环,懂得来
- combobox向datagridview传值过程中如何禁止方向键
- 登录验证,深度判断怎么完不成目的哈?
- 有高手能讲讲派生类实例化时发生的事情嘛?迷茫啦
- 测试用例
- 哪位对C#下应用Oracle 的XMLDB有经验的兄弟?
- 我对c#中的接口理解不是很深刻,希望哪为大侠讲解一下!!!!!!!!!!
- 很简单的问题,关于hellowwordform的
- 绝对植符号是什么?
- 当软件中有ImageFromFile()语句而且软件注册为开机启动时软件会在开机启动时停止
- 各位老大,帮我这个新手看下这段代码是怎么回事,总是报报INSERT INTO 语句的语法错误
- winform中Datagirdview的使用
如果是xml文件的話,下面代碼就可以了.XmlDocument doc = new XmlDocument();
doc.Load("c:\\test.xml");
XmlNodeList list = doc.SelectNodes("//category"); this.DropDownList1.Items.Clear();
for (int i = 0; i < list.Count; i++)
{
this.DropDownList1.Items.Add(new ListItem(list[i].Attributes["name"].Value, list[i].Attributes["CategoryId"].Value));
}