1

有没有办法使用 Linq 将 XML 中的所有现有值替换为字典中的值?我正在使用 c#。

XML 示例:

<root>
  <node1> <--without attribute
    <subNode1>someTextValue</subNode1>
  </node1>
  <node2 name="myNode2"> <--With attribute (IMPORTANT!!!)
    <subNod1>someOtherTextValue</subNode1>
  </node2>
</root>


Dictionary<string, Hashtable> dataFromXML;

dataFromXML Keys从这个例子是node1 (because here is note an attribute), myNode2 (because here is an attribute)......

dataFromXML Values是子节点。

现在假设我们在某个子节点中进行了一些值更改,并且我们想要更新 XML。

我怎么能这样做而不是用foreach循环???

希望我的问题得到明确定义。

编辑

XElement 和 ReplaceWith 函数呢?

最好的问候。

4

1 回答 1

0

我认为您不能在 Linq 查询中更新 XDocument。无论如何,开发 foreach 语句会很容易(相信我,您会浪费更少的时间),并记住 linq 查询被称为循环语句,因此即使您只看到一行代码,循环实际上也存在......

问候

于 2009-12-04T04:46:30.107 回答