forum

Home / DeveloperSection / Forums / Writing online XML file to textbox

Writing online XML file to textbox

Anonymous User 2241 01-Apr-2014

I am using a PHP script to generate xml files. I want to write the data in the XML file to a Textblock in my Windows Phone 8 App. When I debug, I get an error which is not caught my the catch

This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml;
using System.IO;
using System.Xml.Linq;
using System.Diagnostics;
namespace xml1
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create("http://cocktailpws.net23.net/requests/get_cocktail.php?id=10") as HttpWebRequest;
                request.BeginGetResponse(r =>
                {
                    var reponse = request.EndGetResponse(r);
                    //XDocument xmlDoc = XDocument.Load(reponse.GetResponseStream());
                    XmlReader reader = XmlReader.Create(reponse.GetResponseStream());
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element: // Het knooppunt is een element.
                                Console.Write("<" + reader.Name);
                                Console.WriteLine(">");
                                break;
                            case XmlNodeType.Text: //De tekst in elk element weergeven.
                                tb1.Text = tb1.Text + reader.Value + "\r\n";
                                Console.WriteLine(reader.Value);
                                break;
                            case XmlNodeType.EndElement: //Het einde van het element weergeven.
                                Console.Write("</" + reader.Name);
                                Console.WriteLine(">");
                                break;
                        }
                    }
                }, null);
            }
            catch (Exception myExc)
            {
                Console.WriteLine(myExc.Message);
            }
        }
    }
}


c# c# 
Updated on 10-Apr-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By