Hi Everyone,
I am trying to read in a block of xml using the following code, but it always jumps over the foreach loop:
XDocument doc = XDocument.Load(sourceFile);
XElement root = XElement.Load(sourceFile);
var DataRecords = doc.Elements("DATA_RECORD");
foreach (var dr in DataRecords)
{
//build up the values we're interested in
string refno = dr.Attribute("NGIE_REFNO").Value;
string title = dr.Attribute("NGIE_TITLE").Value;
string initials = dr.Attribute("NGIE_INITIALS").Value;
string surname = dr.Attribute("NGIE_SURNAME").Value;
string forename = dr.Attribute("NGIE_FORENAME").Value;
string dob = dr.Attribute("LAG_DOB").Value;
string fullName = dr.Attribute("NGIE_FULL_NAME").Value;
string other_name = dr.Attribute("LAG_PAR_OTHER_NAME").Value;
string gender = dr.Attribute("LAG_PAR_GENDER").Value;
string disabled = dr.Attribute("NGIE_DISABLED_IND").Value;
string risk_ind = dr.Attribute("NGIE_RISK_IND").Value;
string telephone = dr.Attribute("NGIE_TELEPHONE").Value;
string mobile = dr.Attribute("NGIE_MOBILE").Value;
string work = dr.Attribute("NGIE_WORK").Value;
string fax = dr.Attribute("NGIE_FAX").Value;
//and then populate them into the new record
FWTIndividualUpdate fwtIndividualUpdate = new FWTIndividualUpdate();
if (!string.IsNullOrEmpty(dob))
{
fwtIndividualUpdate.DateOfBirthUpdate.DateOfBirth = DateTime.Parse(dob);
}
int result = inUpdate.updateIndividual(fwtIndividualUpdate);
}
With the xml looking like:
<main>
<DATA_RECORD>
<NGIE_REFNO>318</NGIE_REFNO>
<NGIE_TITLE>MISS</NGIE_TITLE>
<NGIE_INITIALS>A</NGIE_INITIALS>
<NGIE_SURNAME>Flogget</NGIE_SURNAME>
<NGIE_FORENAME>H</NGIE_FORENAME>
<LAG_DOB>1969-01-31</LAG_DOB>
<NGIE_FULL_NAME>MISS A Flogget</NGIE_FULL_NAME>
<LAG_PAR_OTHER_NAME />
<LAG_PAR_GENDER>F</LAG_PAR_GENDER>
<NGIE_DISABLED_IND>N</NGIE_DISABLED_IND>
<NGIE_RISK_IND>1</NGIE_RISK_IND>
<LAG_PAR_POST_BOX_NUMBER />
<NGIE_TELEPHONE>TELEPHONE</NGIE_TELEPHONE>
<NGIE_MOBILE>MOBILE</NGIE_MOBILE>
<NGIE_WORK>WORK</NGIE_WORK>
<NGIE_FAX>FAX</NGIE_FAX>
</DATA_RECORD>
</main>
Any ideas would be greatly appreciated.