1
我有一个这样的XML。如何比较xml属性与linq到XML?
<root>
<element attributeId="1" attribute2="1" attribute3="A" />
<element attributeId="1" attribute2="2" attribute3="A" />
<element attributeId="2" attribute2="1" attribute3="A" />
<element attributeId="3" attribute2="1" attribute3="A" />
<element attributeId="3" attribute2="1" attribute3="B" />
</root>
我想比较,改变为具有相同属性Id元素的属性,我创建了一个类来存储的结果是这样的:
public class Result
{
public string AttributeName { get; set; }
public string OldValue { get; set; }
public string NewValue { get; set; }
}
我希望从获得结果列表,我创建了一个变量:
List<Result> result;
如果我运行下面的代码:
foreach (Result item in result)
{
/* Write results */
}
预期的结果将是:
Attribute2 | 1 | 2 (For ID 1)
Attribute2 | 1 | Null (For ID 2 as there is no value to compare)
Attribute3 | A | B (For ID 3)
这必须使用LINQ到XML完成,我已经知道从微软的xmldiff但是这个工具是不是我的选择。我已经花了一个多星期的时间研究并试图解决这个问题。理想的情况是属性的数量会有所改变,并将其作为,因此,如果有人可以找出一种方法做上述相同的XML像
<root>
<element attid="1" aa="1" bb="A" cc="X" />
<element attid="1" aa="2" bb="A" cc="Y" />
<element attid="2" aa="1" bb="A" cc="X" />
<element attid="3" aa="1" bb="A" cc="X" />
<element attid="3" aa="1" bb="B" cc="X" />
</root>
你比较哪些属性?我看到“新”和“旧”,但相比之下呢?你试图比较哪些元素的属性?你在这里说的没有任何意义。 –
对于混淆,基本上我想比较按属性ID分组的相同属性的属性,并获得有差别的属性,在同一个第一个示例中,我可以每个ID获得最多2条记录,每个不同属性获取一条记录。如果没有其他ID进行比较,我应该将两个属性都记录为记录。 –