【发布时间】:2018-04-11 15:42:59
【问题描述】:
文档 1 已满
<_Items>
<_ItemName>COLOR REVOLUTION LIPSTICK</_ItemName>
<_ItemQt>18300</_ItemQt>
<_ItemNumber>1</_ItemNumber>
<_Unit>шт</_Unit>
<_ItemContract>
<_ContractName>03011/1</_ContractName>
<_ContractNumber>AA/001/2016</_ContractNumber>
<_ContractDate>2016-11-24</_ContractDate>
</_ItemContract>
<_ItemCode>3304100000</_ItemCode>
<_ItemCost>352529.07</_ItemCost>
<_ItemPrice>1050.10</_ItemPrice>
</_Items>
文档 2 已部分填充
<_Items>
<_ItemName />
<_ItemQt />
<_Unit />
<_ItemNumber />
<_ItemContract>
<_ContractName />
<_ContractNumber />
<_ContractDate />
</_ItemContract>
<_ItemCode />
<_ItemCostNew>372338.46</_ItemCostNew>
<_ItemCostOld>186169.21</_ItemCostOld>
<_ItemPrice />
</_Items>
那么,如何用文档 1 中的相同元素填充文档 2 中的空值? 我的想法是删除文档 2 中的所有空节点
XDocument xdoc = XDocument.Load(document2);
xdoc.Descendants("Employee")
.Where(e => e.Descendants().Any(d => String.IsNullOrEmpty(d.Value)))
.Remove();
然后从文档 1 中导入所有缺失的元素。但我不知道如何避免覆盖填充节点
【问题讨论】:
标签: c# xml xml-parsing linq-to-xml