0

我有这个 xml 的游戏列表,所有游戏都有里面的单词和图片

<root>
  <game GameID="122" GameName="fer" IdCARDS="5">
    <CARD id="1" pic="~/pic/119.jpg" word="11" />
    <CARD id="3" pic="~/pic/121.jpg" word="22" />
    <CARD id="4" pic="~/pic/122.jpg" word="33" />
  </game>
</root>

我可以更改卡片的顺序并通过以下方式删除它们:

 protected void DownButton_Click(object sender, ImageClickEventArgs e)
       {
          XmlDocument Document = XmlDataSource1.GetXmlDocument();
          string theGAMEId = Label2.Text;
          string cardID = (string)Session["ID2"];
          string cardIDAbove = Convert.ToString(Convert.ToInt16(cardID) + 1);

          string ThePicSource = Convert.ToString(Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardID + "']/@pic").InnerXml);
          string TheWordSource = Convert.ToString(Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardID + "']/@word").InnerXml);
          string ThePicAbove = Convert.ToString(Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardIDAbove + "']/@pic").InnerXml);
           string TheWordAbove = Convert.ToString(Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardIDAbove + "']/@word").InnerXml);


           Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardID + "']/@pic").InnerXml = ThePicAbove;
           Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardID + "']/@word").InnerXml = TheWordAbove;
           Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardIDAbove + "']/@pic").InnerXml = ThePicSource;
           Document.SelectSingleNode("//game[@GameID='" + theGAMEId + "']/CARD[@id='" + cardIDAbove + "']/@word").InnerXml = TheWordSource;

                    XmlDataSource1.Save();
                    GridView1.EditIndex = -1;
                    GridView1.DataBind();

                    Session["ID2"] = cardIDAbove;

                }
            }

当您删除后我想更改位置时会出现问题(然后我没有ID跟随)

那么如何在 XML 中选择 Next Node 和 Before Node

4

0 回答 0