---
title: "Writing online XML file to textbox"  
description: "Writing online XML file to textbox"  
author: "Anonymous User"  
published: 2014-04-01  
updated: 2014-04-10  
canonical: https://www.mindstick.com/forum/2007/writing-online-xml-file-to-textbox  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Writing online XML file to textbox

I am using a PHP [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) to generate xml files. I want to write the [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) in the [XML file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php) to a Textblock in my [Windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [Phone](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) 8 App. When I [debug](https://www.mindstick.com/forum/156/how-to-debug-application-on-the-server), I get an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) which is not caught my the [catch](https://www.mindstick.com/forum/159341/how-to-use-try-and-catch-in-java-for-exception-handling-and-what-happens-when-an-exception-occurs)

**This is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**

```
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);            }        }    }}
```

## Replies

### Reply by Pravesh Singh

Hi Chintoo,

I believe you must access tb1 from the UI thread, so I would suggest trying to use a statement similar to this:

```
case XmlNodeType.Text: //De tekst in elk element weergeven.{    tb1.Dispatcher.BeginInvoke(() =>    {        tb1.Text = tb1.Text + reader.Value + "\r\n";    });    Console.WriteLine(reader.Value);}break;
```


---

Original Source: https://www.mindstick.com/forum/2007/writing-online-xml-file-to-textbox

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
