每行首次出现后,需要删除“分数”的每个实例

时间:2019-03-06 21:43:45

标签: c# asp.net .net xml xpath

<RepairOrderEvent>
      <EventType>Advisor - Shared Guidelines</EventType>
      <EventDateTime>2019-01-07T11:18:38.8756279-06:00</EventDateTime>
      <EventNotes>FAF: Refinish Time without Haz Waste or EPC Charge; Score: 11; Variance: 0.0; UniqueSequenceNum: 0; Insurance Score: 40</EventNotes>
    </RepairOrderEvent>
    <RepairOrderEvent>
      <EventType>Advisor - Shared Guidelines</EventType>
      <EventDateTime>2019-01-07T11:18:38.8756279-06:00</EventDateTime>
      <EventNotes>FAF(Best Practice): Must Enter If Vehicle is Drivable; Score: 11; Variance: 0.0; UniqueSequenceNum: 0</EventNotes>
    </RepairOrderEvent>
    <RepairOrderEvent>
      <EventType>Advisor - Shared Guidelines</EventType>
      <EventDateTime>2019-01-07T11:18:38.8756279-06:00</EventDateTime>
      <EventNotes>FAF(Best Practice): Bumper Overlap Prompt Answered Yes, No Estimate Line Note; Score: 11; Variance: 0.0; UniqueSequenceNum: 2; Insurance Score: 25</EventNotes>
    </RepairOrderEvent>
    <RepairOrderEvent>
      <EventType>Advisor - Shared Guidelines</EventType>
      <EventDateTime>2019-01-07T11:18:38.8756279-06:00</EventDateTime>
      <EventNotes>FAF(Document): Insufficient Photos Provided: Include Damage Area; Score: 11; Variance: 0.0; UniqueSequenceNum: 0; Insurance Score: 10000</EventNotes>
    </RepairOrderEvent>

我有以下XML数据。我正在尝试查找“得分”而非“得分” +“保险得分”的总和。我当时在考虑使用Xpath查找每行中第一个出现的score并删除字符串的其余部分。最终目标是能够读取第一次出现的每一行,删除字符串的其余部分并找到分数的总和。

任何建议或帮助都将受到欢迎和赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

一旦您要处理EventNotes的值,则可以假设每个EventNotes都具有某种“分数”,就可以执行类似的操作。

  var num = eventNotes
    .Select(note => note
      .Split(";")
      .Where(part => part.Contains("Score"))
      .Select(score => int.Parse(score.Split(' ')[1]))
      .First())
    .Aggregate((sum, val) => sum + val);

这将为您提供所有EventNote中分数的所有首次出现的总和。 假设您已经拥有XML解析部分。