Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在XML中选择下一个节点和前一个节点?_C#_Xml - Fatal编程技术网

C# 如何在XML中选择下一个节点和前一个节点?

C# 如何在XML中选择下一个节点和前一个节点?,c#,xml,C#,Xml,我有这个游戏列表的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

我有这个游戏列表的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>
问题发生在我想在你删除后改变位置时(然后我就没有ID了)


那么我如何选择XML中的下一个节点和前一个节点呢?

您可以改用LINQ to XML吗?在我看来,这会使很多事情变得更简单。每当我在代码中看到XmlDocument时,我敢打赌会有一条关于LINQ to Xml的Jon Skeet评论:)
 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;

                }
            }