0

I know this is a very simple question-reading and parsing an xml file and has tons of solutions here already.Could you kindly assist me before shutting down this question?I'm new to C# and Xamarin as well,and have tried tons of solutions already but the result is always the same- nothing gets printed out to the console.Regardless of my implementation.The values are always null.Could you kindly check my code out,i have no idea why i'm not getting any data.

public List<SamplePoint> ReadFromFile()
    {
        pointList = new List<SamplePoint> ();


            xmldoc = new XmlDocument ();
            xmldoc.Load (fileLocation); //this is read from the sdcard of the device

XmlNodeList nodeList = xmldoc.DocumentElement.SelectNodes ("/SamplePoints/SamplePoint");

        foreach(XmlNode node in nodeList){


            endDate = node.SelectSingleNode ("EndDate").InnerText;

            startDate = node.SelectSingleNode ("startDate").InnerText;


return pointsList;
        }
naffie
  • 679
  • 1
  • 12
  • 29
  • The elements are in a namespace. You're not using that namespace. Will find a duplicate now. I'd strongly recommend using LINQ to XML instead of XmlDocument, btw. – Jon Skeet Mar 02 '15 at 12:41
  • @Jon Skeet thank you so much for your quick response.Could you kindly explain what you mean by the elements are in a namespace?I mean,i've worked with C# for a few weeks now and i know what a namespace is,but i don't know what you mean by 'the elements are in a namespace'. – naffie Mar 02 '15 at 12:44
  • 1
    It's not a C# aspect at all - it's XML. Your root element has `xmlns="..."` which means all unqualified elements are in that namespace. See the linked question. – Jon Skeet Mar 02 '15 at 12:45
  • @Jon Skeet i spent weeks literally trying to find out what i was doing wrong.Let me try that and i'll let you know if i succeed.Thanks a lot! – naffie Mar 02 '15 at 13:11
  • @Jon Skeet thank you for pointing me in the right direction.It worked perfectly.I just used the XmlNamespaceManager. – naffie Mar 04 '15 at 21:02
  • If you must - I still think you'd find it a lot easier to use LINQ to XML :) – Jon Skeet Mar 04 '15 at 21:11
  • I've seen a couple of LINQ examples around.Perhaps i'll look into that a little later.Thank you so much.You literally saved me days of debugging!Have you used the sqlite with xamarin.Android before as well? – naffie Mar 04 '15 at 21:18
  • Nope, not at all. But this is now way out of the scope of your question - this isn't a chat. – Jon Skeet Mar 04 '15 at 21:20

0 Answers0