<Catalog>
    <Title>栏目管理</Title>
    <Items>
      <Item>栏目管理0<Item>
  <Item>栏目管理1<Item>
  <Item>栏目管理2<Item>      
    </Items>
  </Catalog>
1、怎么样让dropdownlist读出<Title></Title>里边的内容,然后ListBox自动读取Item里的内容;
2、怎么样把TextBox里的值加到相应的<Title></Title>下边的Item里
3、删除相应的!

解决方案 »

  1.   

    呵呵,沒人來,那我來幫樓主解決吧!
    XMLFile.xml文件內容:
    <?xml version="1.0" encoding="utf-8" ?>
    <Catalog>
      <Title>栏目管理
        <Items>
        <Item>
           栏目管理0
        </Item>
        <Item>
           栏目管理1
        </Item>
        <Item>
           栏目管理2
        </Item>
        </Items>
      </Title>
      <Title>資源管理
        <Items>
          <Item>
            資源管理0
          </Item>
          <Item>
            資源管理1
          </Item>
          <Item>
            資源管理2
          </Item>
        </Items>
      </Title>
    </Catalog>
    //回復問題1:
    XmlDocument xdc = new XmlDocument();
                xdc.Load(Server.MapPath("XMLFile.xml"));            XmlNodeList xnl = xdc.SelectSingleNode("Catalog").ChildNodes;
                foreach (XmlNode node in xnl)
                {
                    if (node.Name == "Title")
                    {
                        DropDownList1.Items.Add(new ListItem(node.FirstChild.Value.Trim()));
                    }
                }
                xdc = null;
      

  2.   

    選中DropDownList1中的Title內容顯示在ListBox1裡,
    有個前提條件是把DropDownList1的autopostback設為True;protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            XmlDocument xdc = new XmlDocument();
            xdc.Load(Server.MapPath("XMLFile.xml"));
            ListBox1.Items.Clear();
            XmlNodeList xnl = xdc.SelectSingleNode("Catalog").ChildNodes;
            foreach (XmlNode node in xnl)
            {
                if (node.FirstChild.Value.Trim() == DropDownList1.SelectedValue)
                {
                    XmlNodeList xnl2 = node.LastChild.ChildNodes;
                    foreach (XmlNode node2 in xnl2)
                    {
                        
                            ListBox1.Items.Add(new ListItem(node2.InnerText.Trim()));
                    }
                }
            }
            xdc = null;
        }
      

  3.   

    2、怎么样把TextBox里的值加到相应的<Title></Title>下边的Item里
    3、删除相应的!
    ---
    XmlDocument xmlDoc=new XmlDocument();
    xmlDoc.Load(Load(Server.MapPath("XMLFile.xml")));
    XmlNodeList nodeList=xmlDoc.SelectSingleNode("Catalog").ChildNodes;
    foreach(XmlNode xn in nodeList)
    {
      if (xn.Name=="Title")
       {
           foreach(XmlNode xmlnode in NodeList) 
    {
      if(xmlnode.InnerText.ToString()==strText)
      {
                  xn.LastChild.RemoveChild(xmlnode);//delete node
       }
              }
          XmlNodeList NodeList=xn.LastChild.ChildNodes;
    string  strText=text.Text.ToString();
    XmlElement xe1=xmlDoc.CreateElement("Item");
    xe1.InnerText=strText; xn.LastChild.AppendChild(xe1);//add node
       }
    }