I have an xml file with a namespace and i can read it properly.It has an outer node,called 'Items' which has multiple child nodes,50 of them.(So 50 child nodes called 'ReceiverPoints').When i check the console,its size is correct i.e 50 but when i check the print out,all the output is a repetition of just the first ReceiverPoint node.
I would like to save each receiver point into the database.According to all the examples i have seen,my implementation seems fine.But it gives me wrong results.Could someone help me see what i'm missing?This is the xml file
public List<ReceiverPoint> ReadFile()
{
receiverList = new List<ReceiverPoint> ();
Console.WriteLine ("Now in read file method :" + fileLocation);
xmldoc = new XmlDocument ();
xmldoc.Load (fileLocation);
XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager (xmldoc.NameTable);
//nameSpaceManager.AddNamespace ("ns", "http://schemas.datacontract.org/2004/07/AristotleService.Models");
nameSpaceManager.AddNamespace ("ns", "http://schemas.datacontract.org/2004/07/GTI.Aristotle.Web.Api.Models");
XmlElement rootElement = xmldoc.DocumentElement;
XmlNodeList nodeList = rootElement.SelectNodes("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint", nameSpaceManager);
ReceiverPoint receiverPoint = new ReceiverPoint ();
foreach(XmlNode childNode in nodeList)
{
receiverPoint.CloseDate = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:CloseDate", nameSpaceManager).InnerText;
receiverPoint.CreateDate = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:CreateDate", nameSpaceManager).InnerText;
receiverPoint.CreateWho = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:CreateWho", nameSpaceManager).InnerText;
receiverPoint.Easting = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:Easting", nameSpaceManager).InnerText;
receiverPoint.Elevation = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:Elevation", nameSpaceManager).InnerText;
receiverPoint.IsDeployed = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:IsDeployed", nameSpaceManager).InnerText;
receiverPoint.IsManual = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:IsManual", nameSpaceManager).InnerText;
receiverPoint.LastModifyDate = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:LastModifyDate", nameSpaceManager).InnerText;
receiverPoint.Latitude = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:LatitudeWGS84", nameSpaceManager).InnerText;
receiverPoint.Line = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:Line", nameSpaceManager).InnerText;
receiverPoint.Longitude = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:LongitudeWGS84", nameSpaceManager).InnerText;
receiverPoint.ReceiverType = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:ReceiverType", nameSpaceManager).InnerText;
receiverPoint.Station = childNode.SelectSingleNode ("/ns:PagedDataInquiryResponseOfReceiverPointQ3ffICf5/ns:Items/ns:ReceiverPoint/ns:Station", nameSpaceManager).InnerText;
//Get all the values stored in the receiver point object
string station = receiverPoint.Station;
string line = receiverPoint.Line;
string elevation = receiverPoint.Elevation;
string latitude = receiverPoint.Latitude;
string longitude = receiverPoint.Longitude;
string isDeployed = receiverPoint.IsDeployed;
string easting = receiverPoint.Easting;
string receiverType = receiverPoint.ReceiverType;
string closeDate = receiverPoint.CloseDate;
string createDate = receiverPoint.CreateDate;
string createWho = receiverPoint.CreateWho;
string lastModifyDate = receiverPoint.LastModifyDate;
Console.WriteLine ("String lat : " + latitude);
Console.WriteLine ("String lon : " + longitude);
Console.WriteLine ("String create date : " + createDate);
Console.WriteLine ("String create who : " + createWho);
//Save the data to the db
saveDataToDatabase (station,line,elevation,latitude,longitude,isDeployed,easting,receiverType,closeDate,createDate,createWho,lastModifyDate);
}
receiverList.Add (receiverPoint);
return receiverList;
}