Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.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,我有这样的想法: <MotionCapture height="480" dialogueFile="none" width="640" fps="30" numFrames="55" depth="200.0"> <MocapFrame index="0"> <Skeleton id="0"> <Joints> <torso x="0,09970227" z="2,13386" y="0,020484

我有这样的想法:

<MotionCapture height="480" dialogueFile="none" width="640" fps="30" numFrames="55" depth="200.0">
  <MocapFrame index="0">
    <Skeleton id="0">
      <Joints>
        <torso x="0,09970227" z="2,13386" y="0,02048468" />
        <neck x="0,139027" z="2,11847" y="0,3753783" />
        <head x="0,1632785" z="2,102617" y="0,5890977" />
        <l_shoulder x="-0,02443917" z="2,124225" y="0,2805836" />
        <r_shoulder x="0,301287" z="2,170277" y="0,2579407" />
        <l_hip x="0,01964889" z="2,067304" y="-0,1138878" />
        <l_knee x="-0,05473036" z="1,961696" y="-0,4850187" />
        <l_foot x="-0,1081518" z="1,841429" y="-0,7449498" />
        <r_hip x="0,1662257" z="2,089662" y="-0,1240771" />
        <r_knee x="0,1636017" z="2,024291" y="-0,5009199" />
        <r_foot x="0,1338794" z="1,972047" y="-0,8106034" />
      </Joints>
    </Skeleton>
  </MocapFrame>
.
.
.
</MotionCapture>

.
.
.
我如何重新排列
关节所包含的儿童
以便
头部
躯干
变换位置

我一直在找,我想不出来


谢谢

使用
LINQ to XML
和方法,这将起作用:


您想如何重新排列它们?您想替换
头部
躯干
元素吗?是的,我想在列表中从头到尾都是您正在生成xml,或者只是将其作为输入接收到您的程序中?这不会用头覆盖躯干吗?@JuanCarlosAllendeMena我在这一行上得到:System.invalidoOperationException:joint.Elements(“head”).Last().replacetwith(temp)@JuanCarlosAllendeMena所有
关节
元素都包含一个
躯干
和一个
头部
对吗?那么它就不会给你这个错误了。我尝试了你的示例xml,它工作正常
var xmlDocument = XDocument.Load("path");
var Joints = xmlDocument.Descendants("Joints");

foreach (var joint in Joints)
{
    var temp = joint.Element("torso");
    joint.Element("torso").ReplaceWith(joint.Element("head"));
    joint.Elements("head").Last().ReplaceWith(temp);
}    
xmlDocument.Save("path");