Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Talk:Employees app with XML parsing and messaging in WP

From Wiki
Jump to: navigation, search


Phuc@realcom - Great post!

Thankyou! this is a great post.

I have a question. Could rendering Employees to screen process comes along with downloading process?

phuc@realcom 15:14, 17 January 2012 (EET)

Pasi.manninen - to Phuc@realcom

XML file will be loaded first and then EmployeesDownloaded method will be called. After that, in EmployeesDownloaded method, data will be binded to ListBox and then all images will be loaded.

pasi.manninen 17:58, 18 January 2012 (EET)

Paoki - Previous Next Employee

Thanks for your post. I have a question. On the Employee Details page I want to have 2 buttons: next and previous, so that if the user clicks on the next button it will automatically bring the next employee data on the employee details page (sameway by clicking on the previous button). could you please let me know how to do that?

thank you

paoki 17:39, 19 February 2012 (EET)

Pasi.manninen - Prev/Next Employee

Hi Paoki,

you have to move employees from MainPage.xaml.cs to App.xaml.cs (same way as selectedEmployee is). In Employee Details page you have to set selectedEmployee to previous or next employee from Employees Collection when buttons are clicked. And finally update view with new employee data.


pasi.manninen 21:51, 28 February 2012 (EET)

Etnad - Great post!!

Great post, thank you for the example. Is it possible to change the email link to link to a pivot page? For an example, if employee is in a category of Day Shift, Night Shift or Swing Shift.. when the user clicks "Night Shift" it takes them to basically an about page that explains the Night Shift? I hope that made sense... anyway great post thanks for sharing.

That was a silly question.. I figured it out. :P

New question.. I can't figure out how to that the xml as a resource instead of requiring an internet connection.

I've tried adding it as a resource then I thought it'd be as simple as changing this, but no luck. I've tried several different things but cant figure it out. any ideas?

           Uri uri = new Uri("/Images/employees.xml", UriKind.Relative);

Etnad 07:16, 30 March 2012 (EEST)

EDIT: I figured that out too... Here's the code if there's other newbies out there.

Place the employees.xml directly under the project and set as Content.

Change MainPage.xaml.cs to:

       public MainPage()
           Uri uri = new Uri("/Employees;component/employees.xml", UriKind.Relative);
           XDocument document = XDocument.Load("employees.xml");
           XmlSerializer serializer = new XmlSerializer(typeof(Employees));
           Employees employees = (Employees)serializer.Deserialize(document.CreateReader());
           employeesList.ItemsSource = employees.Collection;

Then completely comment out the "void EmployeesDownloaded" section.

Woohoo it works!

Okay.. next project, switch this to an LLS :) Anyone help with that?

Kavit Patel - Create Data classes using tool


Great article.

I want to add something here.

You have created ""Employees"" & ""Employee"" Classes manually to parse the XML response using XmlSerializer, creating this class manually requires lots of attention and hence some lengthy process.

We can use the Visual Studio's tool named ""XSD"" to create these classes automatically.

I have written article for the same @



Kavit Patel 15:59, 25 April 2012 (EEST)

Ekzotik - j2me

Hi is it possible to have such a code in j2me.please i request u post a j2me code too.

ekzotik 14:25, 22 May 2012 (EEST)

Javabak - Problem with the feed

Hey there, nice explaination, works great but not in my case :(

I have this application that shows events in my city, every event got an image and a title and if I click an event I'll go to the detail page that show me the larger image, the title and the description, everything similar to this example and in fact it works pretty fine, the problem? it shows me only one event, it seem that the deserialization stop workingafter the first one :\

here you can see the feed that i use:

this is my Events class:

namespace Bluey
   public class Eventi
       public ObservableCollection<Evento> Collect { get; set; }

and this is my Event class

namespace Bluey
    public class Evento
        public string title { get; set; }
        public string image { get; set; }
        public string description { get; set; }

any help would be apreciated, tnx in advice!


Javabak 14:30, 13 August 2012 (EEST)

Hamishwillee - You might want to private message Pasi direclty

Hi Guys

If you're asking about something directly related to this article then by all means post here. However I suggest you also send a private message Pasi by hovering over his name up in the ArticleMetaData. This increases the likelihood he will get the message - as he may not be monitoring the article anymore.

If however your question is only peripherally related to the article (for example a request for java me code that does the same thing!) then I suggest you raise a discussion board post on the Windows Phone forum - you can of course cross link to the article.

This increases the chance that you will get support.

Regards Hamish

(Community Manager, Nokia)

hamishwillee 07:16, 15 August 2012 (EEST)

Nayana Bingi - Problem in ObservableCollection part

Hi, I have tried to retrieve the XML data from the site "".. but the result i am getting is a blank page . The following is the content of xml file

<?xml version="1.0" encoding="UTF-8"?> <articles>

 <link></link> -<item>
   <title>CAT All Set to Go International</title> -<description>
     <![CDATA[CATapp first published this news on April 15, 2012. But it has again come to limelights. So now NRIs (Non Residential Indians) and PIOs (People of Indian Origin) will be able to appear for CAT 2013. CAT could also be conducted exclusively for international B-schools. Such institutes in countries like Nepal, Sri Lanka and West Asia want the IIMs to conduct CAT. At present, most admissions at these B-schools are through GMAT. Read the entire news <a href="">here</a>]]>
   </description> <pubdate>2012-10-25</pubdate>
 </item> -<item>
   <title>IIM-B will refund fees of students opting for NGO Placements</title> -<description>

The Indian Institute of Management, Bangalore (IIM-B) will refund the fees of around Rs 8 lakh that students pay for their two-year Post Graduate Programme (PGP) if they take up a job in any non-profit entity (NGO) and work there for at least three years.

Students who work in an NGO for a year, too, could get a part-waiver of their fees.

IIM-B officials explained that the decision was taken because a number of students had expressed a desire to work with NGOs over the past few years but were concerned about their finances.

The institute believes the move will encourage many of its students to gain a different kind of work experience, simultaneously helping people at the grassroots level.

"We have NGOs like Teach For India and Azim Premji Foundation coming to campus. We have had Narayana Hrudayalaya make a pre-placement talk to students," said Sapna Agarwal, head of career development services at IIM-B.

   </description> <pubdate>2012-10-12</pubdate>


This is the Articles.cs file -- namespace t4 {

   public class Articles
       public ObservableCollection<Article> Collection { get; set; }


This is the Article.cs file-- namespace t4 {

   public class Article
       public string title { get; set; }
       public string description { get; set; }
       public string pubdate { get; set; }


This is my MainPage.xaml.cs file-- namespace t4 {

   public partial class MainPage : PhoneApplicationPage
       // Constructor
       public MainPage()
           // is there network connection available
              if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                  MessageBox.Show("No network connection available!");
              // start loading XML-data
              WebClient downloader = new WebClient();
              Uri uri = new Uri("",UriKind.Absolute);
              downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(NewsDownloaded);
          void NewsDownloaded(object sender, DownloadStringCompletedEventArgs e)
              if (e.Result == null || e.Error != null)
                  MessageBox.Show("There was an error downloading the XML-file!");
                  // Deserialize if download succeeds
                  XmlSerializer serializer = new XmlSerializer(typeof(Articles));
                  XDocument document = XDocument.Parse(e.Result);
                  // get all the news
                  Articles news = (Articles)serializer.Deserialize(document.CreateReader());
                  // bind data to ListBox
                  newsList.ItemsSource = news.Collection;
       private void newsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
           var app = App.Current as App;
           app.selectedNews = (Article) newsList.SelectedItem;
           this.NavigationService.Navigate(new Uri("/Detailnews.xaml", UriKind.Relative));

There are no errors .. but the output that i get is a blank page .. when i debugged the NewsDownloaded () fuction the contents of locals stack are as shown DEFAULT_NAMESPACES Cannot fetch the value of field 'DEFAULT_NAMESPACES' because information about the containing class is unavailable. System.Xml.Serialization.XmlSerializerNamespaces in serializer variable.

Please Suggest solution for this problem

Thanks and Regards


Nayana Bingi 08:21, 16 February 2013 (EET)

Pooja 1650 - Corrected Broken Link

Hi Passi,

The link to PhonePerformance.dll was broken so I had just replaced it with the one mentioned in your other article "Weather in Windows Phone". Please check it once and correct me If I am wrong.



pooja_1650 08:06, 4 March 2013 (EET)

Pasi.manninen - Pooja - Correct link


now it is correct again.



pasi.manninen 10:13, 18 March 2013 (EET)

Kunal Chowdhury -

Great post. Thank you for sharing.


Kunal Chowdhury

Kunal Chowdhury (talk) 21:36, 11 August 2013 (EEST)

Ardit dine - Error Changing Uri

Hello, great post.

I'm haveing problem when i navigate to different employee all data are display correct but when i go back where are all the employee list and press a button that change the uri of the xml it gave me a error on EmployeePage.xaml

ardit_dine (talk) 13:37, 6 November 2013 (EET)

Hamishwillee - Ardit dine - thanks for posting

Hi Ardit dine

If you cab debug this yourself and update it would be great. If you don't get a reply in a few days you might want to sent a private message to the author pasi.manninen (just hover over his name to see option to send)



hamishwillee (talk) 05:23, 7 November 2013 (EET)

Chintandave er - Is there easy way to search, filter data ?

Hi, Thanks for this article.

Is there easy way to search employee by his name and other details ?

Chintandave er 09:19, 9 February 2014 (EET)

Microasif - How can we search ?

hey, Great article;

How can we search from this Employees collection ??

Microasif (talk) 13:06, 2 March 2014 (EET)

GTO India - I trying buld a live tva nd vod App but facing problem in parsing or showing the channel images from the url

I have followed this article . Your article is very helpfuland great.

Please guide me How to Pull and show the channel names , images and url's by parsing from the xml contained in the url

My xml file in the url is the below format:



GTO_India (talk) 08:38, 17 July 2014 (EEST)

GTO India - Please fix the issue my images are not getting downloaded and shown

Please fix the issue where Iam wrong in parsing methods

Here are the parsing lines

      void VodChannelsDownloaded(object sender, DownloadStringCompletedEventArgs e)
           if (e.Result == null || e.Error != null)
               MessageBox.Show("There was an error downloading the XML-file!");
               // Deserialize if download succeeds
               XmlSerializer serializer = new XmlSerializer(typeof(VodChannels));
               XDocument document = XDocument.Parse(e.Result);
              VodChannels MYVODS = (VodChannels) serializer.Deserialize(document.CreateReader());
               vodchannelsList.ItemsSource = MYVODS.Collection;
       // selection in EmployeeList is changed
       private void vodchannelsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
           var app = App.Current as App;
           app.selectedVodChannel = (VodChannel) vodchannelsList.SelectedItem;
           this.NavigationService.Navigate(new Uri("/VodChannelPage.xaml", UriKind.Relative));


Where my xml file is as follows

This XML file does not appear to have any style information associated with it. The document tree is shown below.

     <rsp><MYVODS><VodDates></VodDates><vodchannels><vodchannel><id>47</id><name>SVBC</name><imgurl></imgurl></vodchannel><vodchannel><id>4</id><name>ABN Andhra Jyothi  High Quality</name><imgurl></imgurl></vodchannel>

Somebody please fix the issue

GTO_India (talk) 16:29, 17 July 2014 (EEST)

SKUMAR - HI Kavit Patel I have used your method i.e xsd tool- and article Create Data classes using tool

I have succesfully created .cs and .xd files using the xsd tool.

But Iam very much canfused at MainPage.xaml.cs

Errors: 1) The name 'xmlResponseString' does not exist in the current context

2) The name 'Encoding' does not exist in the current context


//Get the Memory Stream from the response string. Byte[] memBytes = Encoding.UTF8.GetBytes(xmlResponseString); MemoryStream ms = new MemoryStream(memBytes);

Here, xmlResponseString is the string containing the response of your web request. We are creating a memory stream from this response string.

//Create the XmlSerializer XmlSerializer serializer = new XmlSerializer(typeof(students));

Initialize the new instance of XmlSerializer. Its constructor accepts the Type to be de-serialized to - in this case your data class.

//Deserialize memory stream. students sd = (students) serializer.Deserialize(ms);

in the web page

and what to do with [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "")] [global::System.Serializable()] [global::System.ComponentModel.DesignerCategoryAttribute("code")] [global::System.ComponentModel.ToolboxItem(true)] [global::System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedDataSetSchema")] [global::System.Xml.Serialization.XmlRootAttribute("MYVODS")] [global::System.ComponentModel.Design.HelpKeywordAttribute("")] conatined in the autogenerated .cs file.

How to define them in the code

shall I prefix the above with using like uisng global::System.Serializable(); etc


SKUMAR (talk) 15:21, 18 July 2014 (EEST)