小编Saj*_*jid的帖子

找到重复的xelements

我有以下XML

<Automobiles>
  <Cars>
    <YearofMfr>2010</YearofMfr>
    <Mileage>12</Mileage>
    <MeterReading>1500</MeterReading>
    <Color>Red</Color>
    <Condition>Excellent</Condition>
  </Cars>
  <Cars>
    <YearofMfr>2010</YearofMfr>
    <Mileage>12</Mileage>
    <MeterReading>1500</MeterReading>
    <Color>Red</Color>
    <Condition>Excellent</Condition>
  </Cars>
  <Cars>
    <YearofMfr>2008</YearofMfr>
    <Mileage>11</Mileage>
    <MeterReading>20000</MeterReading>
    <Color>Pearl White</Color>
    <Condition>Good</Condition>
  </Cars>
</Automobiles>
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个返回重复节点的LINQ查询.在上面的XML中有两个相似的节点.结果应包括重复的节点.

我还需要一个查询,它将返回所有不重复的节点.请帮忙.

xml linq group-by distinct duplicates

1
推荐指数
2
解决办法
2353
查看次数

如何计算where子句中的子XElements

<Automobiles>
  <Cars>
    <YearofMfr></YearofMfr>
    <Mileage></Mileage>
    <MeterReading></MeterReading>
    <Color></Color>
    <Condition></Condition>
  </Cars>
  <Cars>
    <YearofMfr></YearofMfr>
    <Color></Color>
    <Condition></Condition>
  </Cars>
</Automobiles>
Run Code Online (Sandbox Code Playgroud)

如何获得包含所有子元素的元素.详细解释.我有上面的xml.从这里我想要检索具有所有子节点的单个节点.如果您在第二个节点中看到某些信息丢失.我试过这样做.

var nodes = from nodeElements in doc.Descendants().FirstOrDefault().Elements()
                 where doc.Descendants().Count()==5
                select nodeElements;
Run Code Online (Sandbox Code Playgroud)

我需要一个节点作为输出,它有5个子元素.

<Cars>     
<YearofMfr></YearofMfr>     
<Mileage></Mileage>     
<MeterReading></MeterReading>     
<Color></Color>     
<Condition></Condition>   
</Cars>
Run Code Online (Sandbox Code Playgroud)

xml linq xelement linq-to-xml

0
推荐指数
1
解决办法
2307
查看次数

标签 统计

linq ×2

xml ×2

distinct ×1

duplicates ×1

group-by ×1

linq-to-xml ×1

xelement ×1