Why don't you serialize it instead of doing it manually ?
With your data I've just made a console program, give it a try
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var result = Serializer.Deserialize();
foreach(var item in result.Body.GetProductListResult.Products.Product)
{
Console.WriteLine("{0}", item.CountryCode);
Console.WriteLine("{0}", item.CountryName);
Console.WriteLine("{0}", item.CustomerCareNumber);
}
}
}
public static class Serializer
{
public static Envelope Deserialize()
{
var type = typeof (Envelope);
var serializer = new XmlSerializer(type);
var xmlString = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<GetProductListResult xmlns=""http://EDTS.DirectTopUpServices.DataTypes/2006/10"">
<MessageID>810190215</MessageID>
<Products>
<Product>
<CountryID>59</CountryID>
<CountryISO>LK</CountryISO>
<CountryCode>LK</CountryCode>
<CountryName>Sri Lanka</CountryName>
<OperatorID>48</OperatorID>
<OperatorCode>DG</OperatorCode>
<OperatorName>Dialog Sri Lanka</OperatorName>
<CustomerCareNumber>+94-77767-8678</CustomerCareNumber>
<PhoneNumberMask>+94-xxxxx-xxxx </PhoneNumberMask>
<MinMaxValueRange>
<MinValue>5</MinValue>
<MaxValue>250</MaxValue>
</MinMaxValueRange>
</Product>
<Product>
<CountryID>60</CountryID>
<CountryISO>PH</CountryISO>
<CountryCode>PH</CountryCode>
<CountryName>Philippines</CountryName>
<OperatorID>54</OperatorID>
<OperatorCode>TM</OperatorCode>
<OperatorName>Touch Mobile Philippines</OperatorName>
<CustomerCareNumber>+63-2370-1000</CustomerCareNumber>
<PhoneNumberMask>+63-xxxxx-xxxxx </PhoneNumberMask>
<Denominations>
<NumberOfDenominations>5</NumberOfDenominations>
<Denominations>
<double>6</double>
<double>16</double>
<double>31</double>
<double>51</double>
<double>102</double>
</Denominations>
</Denominations>
</Product>
<Product>
<CountryID>59</CountryID>
<CountryISO>LK</CountryISO>
<CountryCode>LK</CountryCode>
<CountryName>Sri Lanka</CountryName>
<OperatorID>58</OperatorID>
<OperatorCode>TI</OperatorCode>
<OperatorName>Etisalat Sri Lanka</OperatorName>
<CustomerCareNumber>+ (94) 72212-3123 </CustomerCareNumber>
<PhoneNumberMask>+94-xxxxx-xxxx </PhoneNumberMask>
<MinMaxValueRange>
<MinValue>5</MinValue>
<MaxValue>250</MaxValue>
</MinMaxValueRange>
</Product>
<Product>
<CountryID>55</CountryID>
<CountryISO>PK</CountryISO>
<CountryCode>PK</CountryCode>
<CountryName>Pakistan</CountryName>
<OperatorID>80</OperatorID>
<OperatorCode>WP</OperatorCode>
<OperatorName>Warid Pakistan</OperatorName>
<CustomerCareNumber>+92-32184-34357</CustomerCareNumber>
<PhoneNumberMask>+92-xxxxx-xxxxx </PhoneNumberMask>
<MinMaxValueRange>
<MinValue>5</MinValue>
<MaxValue>250</MaxValue>
</MinMaxValueRange>
</Product>
<Product>
<CountryID>55</CountryID>
<CountryISO>PK</CountryISO>
<CountryCode>PK</CountryCode>
<CountryName>Pakistan</CountryName>
<OperatorID>89</OperatorID>
<OperatorCode>UF</OperatorCode>
<OperatorName>Ufone Pakistan</OperatorName>
<CustomerCareNumber>+92-51111-333100</CustomerCareNumber>
<PhoneNumberMask>+92-xxxxx-xxxxx </PhoneNumberMask>
<MinMaxValueRange>
<MinValue>5</MinValue>
<MaxValue>250</MaxValue>
</MinMaxValueRange>
</Product>
</Products>
</GetProductListResult>
</soap:Body>
</soap:Envelope>";
using (var stringReader = new StringReader(xmlString))
{
return serializer.Deserialize(stringReader) as Envelope;
}
}
}
[XmlRoot(ElementName="MinMaxValueRange", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public class MinMaxValueRange {
[XmlElement(ElementName="MinValue", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string MinValue { get; set; }
[XmlElement(ElementName="MaxValue", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string MaxValue { get; set; }
}
[XmlRoot(ElementName="Product", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public class Product {
[XmlElement(ElementName="CountryID", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string CountryID { get; set; }
[XmlElement(ElementName="CountryISO", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string CountryISO { get; set; }
[XmlElement(ElementName="CountryCode", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string CountryCode { get; set; }
[XmlElement(ElementName="CountryName", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string CountryName { get; set; }
[XmlElement(ElementName="OperatorID", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string OperatorID { get; set; }
[XmlElement(ElementName="OperatorCode", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string OperatorCode { get; set; }
[XmlElement(ElementName="OperatorName", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string OperatorName { get; set; }
[XmlElement(ElementName="CustomerCareNumber", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string CustomerCareNumber { get; set; }
[XmlElement(ElementName="PhoneNumberMask", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string PhoneNumberMask { get; set; }
[XmlElement(ElementName="MinMaxValueRange", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public MinMaxValueRange MinMaxValueRange { get; set; }
[XmlElement(ElementName="Denominations", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public Denominations Denominations { get; set; }
}
[XmlRoot(ElementName="Denominations", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public class Denominations {
[XmlElement(ElementName="double", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public List<string> Double { get; set; }
}
[XmlRoot(ElementName="Products", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public class Products {
[XmlElement(ElementName="Product", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public List<Product> Product { get; set; }
}
[XmlRoot(ElementName="GetProductListResult", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public class GetProductListResult {
[XmlElement(ElementName="MessageID", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public string MessageID { get; set; }
[XmlElement(ElementName="Products", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public Products Products { get; set; }
[XmlAttribute(AttributeName="xmlns")]
public string Xmlns { get; set; }
}
[XmlRoot(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public class Body {
[XmlElement(ElementName="GetProductListResult", Namespace="http://EDTS.DirectTopUpServices.DataTypes/2006/10")]
public GetProductListResult GetProductListResult { get; set; }
}
[XmlRoot(ElementName="Envelope", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope {
[XmlElement(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName="soap", Namespace="http://www.w3.org/2000/xmlns/")]
public string Soap { get; set; }
[XmlAttribute(AttributeName="xsi", Namespace="http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName="xsd", Namespace="http://www.w3.org/2000/xmlns/")]
public string Xsd { get; set; }
}