I am parsing a huge XML using for-loops,SelectNodes,Attributes.GetNamedItem etc.
I came across an issue of how to parse the identical nodes CustLoyalty that are identical as shown in the abstract below. The issue is how to get the identical noded values since they are not exclusively inside a parent node
<Customer>
<PersonName>
<NamePrefix>Ms</NamePrefix>
<GivenName>Fra</GivenName>
<Surname>etti</Surname>
</PersonName>
<Telephone FormattedInd="false" PhoneLocationType="6" PhoneNumber="10" PhoneTechType="1"/>
<Telephone FormattedInd="false" PhoneLocationType="6" PhoneNumber="49" PhoneTechType="3"/>
<Email DefaultInd="true" EmailType="1">z@z</Email>
<Address Type="1">
<AddressLine>alace</AddressLine>
<StateProv StateCode="NY"/>
<CountryName Code="GB"/>
</Address>
<CustLoyalty MembershipID="3" ProgramID="Guest"/>
<CustLoyalty MembershipID="6" ProgramID="Freq"/>
<CustLoyalty MembershipID="56" ProgramID="teID"/>
<CustLoyalty MembershipID="N6" ProgramID="ID"/>
</Customer>
My code goes something like that:
XmlNodeList CustomerList = ProfileList[v].SelectNodes("df:Customer", mgr);
for (int w = 0; w < CustomerList.Count; w++)
{
XmlNodeList PersonNameList = CustomerList[w].SelectNodes("df:PersonName", mgr);
for (int x = 0; x < PersonNameList.Count; x++)
{
XmlNode NamePrefixNode = PersonNameList[x].SelectSingleNode("df:NamePrefix", mgr);
string NamePrefix = NamePrefixNode.InnerText;
XmlNode GivenNameNode = PersonNameList[x].SelectSingleNode("df:GivenName", mgr);
string GivenName = GivenNameNode.InnerText;
XmlNode SurnameNode = PersonNameList[x].SelectSingleNode("df:Surname", mgr);
string Surname = SurnameNode.InnerText;
myProfiles.GivenName = GivenName;
myProfiles.Surname = Surname;
myProfiles.NamePrefix = NamePrefix;
}
XmlNode TelephoneNode = CustomerList[w].SelectSingleNode("df:Telephone", mgr);
if (TelephoneNode != null)
{
string PhoneNumber = TelephoneNode.Attributes.GetNamedItem("PhoneNumber").Value;
myProfiles.Telephone = PhoneNumber;
}..........