0

I am re-wording this from an original post I made: I have two XML files, and they are related to a given year each. For example, 18/19 and 17/18. They conform to the same structure and below is small sample from one of these files. What I want is, in C#, to compare all records in these files where the Given Name, the Family Name, the NI Number and the Date of birth are the same, BUT the Learner Ref Number is different. I need to be able to compare, then push only these records into a data table so I can then push them into a spreadsheet (the spreadsheet bit I can do). I currently have the below as a starting block, but am still very much stuck.

Firstly, I have my Import button press for which:

private void Btn_Import_Click(object sender, RoutedEventArgs e)
{
    ILRChecks.ILRReport.CrossYear();
}

Then this goes to look at the Class of which eventually pushes the file to my location:

using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ILRValidation;
using InfExcelExtension;

namespace ILRChecks
{
    internal static partial class ILRReport
    {
       internal static void CrossYear()
       {
           DataSet ds_CrossYearChecks = 
ILRValidation.Validation.CrossYearChecks(Global.fileNames);
           string output = Path.Combine(Global.foldername, "ULIN_Issues" + 
".xlsx");
           ds_CrossYearChecks.ToWorkBook(output); 
      }
   }
}

And this is the bit I'm stuck on, which is the production of finding the differences:

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILRValidation
{
     public static partial class Validation
    {
          public static DataSet CrossYearChecks(DataSet ds_CrossYearChecks)
         {
              return CrossYearChecks(ds_CrossYearChecks);
         }

         public static DataSet CrossYearChecks(string[] xmlPath)
         {
              DataSet ds_xmlCrossYear = new DataSet();  
              return CrossYearChecks(ds_xmlCrossYear);
         }
     }
}

XML:

<Learner>
<LearnRefNumber></LearnRefNumber>
<ULN></ULN>
<FamilyName></FamilyName>
<GivenNames></GivenNames>
<DateOfBirth></DateOfBirth>
<Ethnicity></Ethnicity>
<Sex></Sex>
<LLDDHealthProb></LLDDHealthProb>
<NINumber></NINumber>
<PriorAttain></PriorAttain>
<MathGrade></MathGrade>
<EngGrade></EngGrade>
<PostcodePrior></PostcodePrior>
<Postcode></Postcode>
<AddLine1></AddLine1>
<AddLine3></AddLine3>
<Email></Email>
<LearnerEmploymentStatus>
  <EmpStat>10</EmpStat>
  <DateEmpStatApp>2015-09-01</DateEmpStatApp>
  <EmpId>153421665</EmpId>
  <EmploymentStatusMonitoring>
    <ESMType>LOE</ESMType>
    <ESMCode>4</ESMCode>
  </EmploymentStatusMonitoring>
  <EmploymentStatusMonitoring>
    <ESMType>EII</ESMType>
    <ESMCode>4</ESMCode>
  </EmploymentStatusMonitoring>
</LearnerEmploymentStatus>
<LearningDelivery>
  <LearnAimRef></LearnAimRef>
  <AimType></AimType>
  <AimSeqNumber></AimSeqNumber>
  <LearnStartDate></LearnStartDate>
  <LearnPlanEndDate></LearnPlanEndDate>
  <FundModel></FundModel>
  <ProgType></ProgType>
  <StdCode></StdCode>
  <DelLocPostCode></DelLocPostCode>
  <CompStatus></CompStatus>
  <SWSupAimId></SWSupAimId>
  <LearningDeliveryFAM>
    <LearnDelFAMType></LearnDelFAMType>
    <LearnDelFAMCode></LearnDelFAMCode>
    <LearnDelFAMDateFrom></LearnDelFAMDateFrom>
  </LearningDeliveryFAM>
  <LearningDeliveryFAM>
    <LearnDelFAMType></LearnDelFAMType>
    <LearnDelFAMCode></LearnDelFAMCode>
  </LearningDeliveryFAM>
  <LearningDeliveryFAM>
    <LearnDelFAMType></LearnDelFAMType>
    <LearnDelFAMCode></LearnDelFAMCode>
  </LearningDeliveryFAM>
  <LearningDeliveryFAM>
    <LearnDelFAMType></LearnDelFAMType>
  • can you check this reference https://stackoverflow.com/questions/794331/xml-comparison-in-c-sharp – Saravanakumar Natarajan Feb 11 '19 at 09:53
  • It's sort of helpful, but I think my scenario isn't quite the same to be wholly relevant –  Feb 11 '19 at 09:56
  • The best way is to put data into datatables and then compare the datatables. There are lots of example on web how to compare two datatables. – jdweng Feb 11 '19 at 09:57
  • That's exactly what I need @jdweng. Just finding the right web resource for this is quite trying to say the least. I'll keep look all the same. –  Feb 11 '19 at 09:58
  • One More way is , You can convert this Compare A.xml and Compare B.xml as a Model using serialization. And compare those models. – Saravanakumar Natarajan Feb 11 '19 at 09:59
  • I can easily do the job. Need a bigger sample of xml the contains at least two repeating nodes. I can't tell from xml you posted what the parent(s) nodes are. – jdweng Feb 11 '19 at 10:05
  • Sure thing, @jdweng. I'll add it to the original question –  Feb 11 '19 at 10:06
  • @jdweng, i've made changes - hopefully it helps. –  Feb 11 '19 at 10:10
  • The parent node is "Learner", I think –  Feb 11 '19 at 10:31
  • The same as https://stackoverflow.com/q/54577516/? – Vlad Feb 11 '19 at 10:37
  • Yea, that was my original –  Feb 11 '19 at 10:43
  • The issue rally is the List objects like LearningDeliveryFAM that makes the task complicated. Presently do you have a database schema that defines the tables and columns in each table? I would start by defining the database structure if you do not already have one. The best way of doing the comparison is to first parse xml to structures that match the database.List objects like LearningDeliveryFAM should be put in a separate table with a primary key that can be joined to other tables because there are many for each employee. I would need to know the database structure before parsing the xml. – jdweng Feb 11 '19 at 11:05

0 Answers0