[英]XML File with same elements
在閱讀現有的XML文檔方面,我遇到了一個小問題(對我來說這是一個大問題)。 我有一個文件,其中包含許多始終相同的元素。 我需要創建一個清單,清楚地表明哪個孩子屬於哪個父母。
<?xml version="1.0" encoding="utf-16"?>
<componentTree name="Location">
<componentRef ref="47350">
<componentRef ref="47379">
<componentRef ref="47425">
<componentRef ref="47471" />
<componentRef ref="47494" />
<componentRef ref="47517">
<componentRef ref="47632" />
<componentRef ref="47655" />
<componentRef ref="47678" />
</componentRef>
</componentRef>
</componentRef>
<componentRef ref="47402">
<componentRef ref="47448">
<componentRef ref="47540">
<componentRef ref="47563">
<componentRef ref="47586" />
<componentRef ref="47609" />
</componentRef>
</componentRef>
</componentRef>
</componentRef>
</componentRef>
</componentTree>
作為47517組件47517父母的一個例子:47425有孩子:是的
有人給我一個提示嗎?
非常感謝...
你可以使用Linq到SQl這樣的東西
XElement doc = XElement.Parse(xml);
var result = (from item in doc.Descendants("componentRef")
select new {Ref = (string)item.Attribute("ref"), Parent = (string)item.Parent.Attribute("ref"), HasChild = item.FirstNode != null }).ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.