0

i have a XML file that should be loaded on ASP MVC, i got the data from my Service, but failed parsing, idk why but the data can't go through List. Here my code

XML File

<ArrayOfNews xmlns="http://schemas.datacontract.org/2004/07/DIESWCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<News>
<CompID>70101</CompID>
<Descriptions>as the winner of awards</Descriptions>
<ImgPath>Company/UI.png</ImgPath>
<Title>University of Indonesia Animate Version</Title>
</News>
</ArrayOfNews>

Models

    public class News
    {
        private int _compid;
        private string _title, _desc, _img;
        public int CompID
        {
            get { return _compid; }
            set { _compid = value; }
        }
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        public string Descriptions
        {
            get { return _desc; }
            set { _desc = value; }
        }
        public string ImgPath
        {
            get { return _img; }
            set { _img = value; }
        }
    }

Process

public List<News> GetViewNews()
    {

      List<News> newslist = new List<News>();
      XmlDocument doc = new XmlDocument();
      doc.Load(SU.URLService() + "ViewNews");
      foreach (XmlNode feed in doc.SelectNodes("/ArrayOfNews/News"))
       {
          newslist.Add(new News
           {                       
             CompID = Convert.ToInt32(feed["CompID"].InnerText),
             Title = feed["Title"].InnerText,
             ImgPath = feed["http://localhost:54654/" + "ImgPath"].InnerText,
             Descriptions = feed["Descriptions"].InnerText
            });
       }           
       return newslist;
   }

When i try to breakpoints on doc line, i got the data but however the return always gives 0 count. Any Idea?

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
blacoffees
  • 43
  • 7
  • @CodeNotFound can you give me an example? – blacoffees May 28 '17 at 15:50
  • Yes it works perfectly. I got the data but failed on XmlNode line – blacoffees May 28 '17 at 15:52
  • Side note: please re-read [MCVE] guidance to avoid posting large amount of code most of which is not related to the problem. I.e. if you can't select a node from Xml there is no point in showing some class unless your question is actually about deserializing XML to class. – Alexei Levenkov May 28 '17 at 17:41

0 Answers0