i want to convert this code which i used it for reading xml files from windows 7 phone to winrt8
-
Sunday, September 16, 2012 1:06 PM
I used this code to read xml file in windows phone now i want to support winrt8 but the webclient api is not found can some one convert it to the proper format to read xml files
{WebClient downloader = new WebClient(); Uri uri = new Uri("http://app..org/Ap/super/shv04.xml", UriKind.Absolute); downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EmployeesDownload); downloader.DownloadStringAsync(uri); } void EmployeesDownload(object sender, DownloadStringCompletedEventArgs e) { // Deserialize if download succeeds XmlSerializer serializer = new XmlSerializer(typeof(Employees)); XDocument document = XDocument.Parse(e.Result); Employees employees = (Employees)serializer.Deserialize(new StringReader(e.Result)); employeesList.ItemsSource = employees.Collection.Where(emp => emp.control.Contains("featured")).ToList(); }
my xml file look like this
<root><employees><employee><control>featured</control><title>Old Referee</title><video>http://app..org/v//.mp4</video><picture>http://img.youtube.com/vi/pkYJQbl4vBg/1.jpg</picture><categories>workout</categories></employee><employee><control>featured</control><title> English movie</title><video>http://app..org/v//119__movie.mp4</video><picture>http://img.youtube.com/vi/UtEFm0QftOU/1.jpg</picture><categories>celebrity</categories></employee>
</root>
the type look like this
namespace Employees
{
public class Employee
{
[XmlElement("control")]
public string control { get; set; }
[XmlElement("title")]
public string title { get; set; }
[XmlElement("video")]
public string video { get; set; }
[XmlElement("picture")]
public string picture { get; set; }}
namespace Employees
{
[XmlRoot("root")]
public class Employees
{
[XmlArray("employees")]
[XmlArrayItem("employee")]
public ObservableCollection<Employee> Collection { get; set; }
}
}
- Edited by vensilver Sunday, September 16, 2012 1:11 PM
- Moved by Min ZhuMicrosoft Contingent Staff, Moderator Tuesday, September 18, 2012 5:20 AM (From:XML, System.Xml, MSXML and XmlLite)
All Replies
-
Tuesday, September 18, 2012 8:29 PMModerator
There's a wealth of information in our samples on how to download information into a Store app:
http://code.msdn.microsoft.com/windowsapps/Windows-8-Modern-Style-App-SamplesMatt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces. -
Tuesday, September 18, 2012 8:33 PM
public async void LoadData() { HttpClient downloader = new HttpClient(); Uri uri = new Uri("http://app..org/Ap/super/shv04.xml", UriKind.Absolute); var str = await downloader.DownloadStringAsync(uri); XmlSerializer serializer = new XmlSerializer(typeof(Employees)); XDocument document = XDocument.Parse(string); Employees employees = (Employees)serializer.Deserialize(new StringReader(str)); employeesList.ItemsSource = employees.Collection.Where(emp => emp.control.Contains("featured")).ToList(); }
this should be it..- Proposed As Answer by Matt SmallMicrosoft Employee, Moderator Wednesday, September 19, 2012 2:47 PM
- Edited by Dave SmitsMicrosoft Community Contributor Wednesday, September 19, 2012 3:23 PM
-
Thursday, September 20, 2012 10:45 AM
i am getting this error Error
1 Invalid expression term 'string' G:\Users\\Documents\Visual Studio 2012\Projects\Employees\Employees\Employees\MainPage.xaml.cs 77 53 Employees
Solve your Problems @ http://www.livetut.com/
-
Sunday, October 21, 2012 7:25 AM
please refer following site
http://swcodeviewer.blogspot.in/2012/03/how-to-read-xml-data-in-windows-8.html

