用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)

解决方案 »

  1.   

    可是XML在另外一个文件?没有什么简单点的方法吗 ?~
      

  2.   

    不好意思,還以為是在數據庫里的.
    如果是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));
                }