Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1105793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:41:26+00:00 2026-05-17T01:41:26+00:00

I have a method that generates XML for a class I have created -getXML().

  • 0

I have a method that generates XML for a class I have created -getXML(). This is called from the following methods:

private void send_Response()
    {
        String xmlUrl = ((App)Application.Current).Resources["xmlUrl"].ToString();
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(xmlUrl,              UriKind.Absolute));
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
    }

    void RequestReady(IAsyncResult asyncResult)
    {
        HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
        Stream stream = request.EndGetRequestStream(asyncResult);
        StreamWriter writer = new StreamWriter(stream);
        writer.WriteLine("assessmentXml=" + assessment.getXML(testComplete));
        writer.Flush();
        writer.Close();

        request.BeginGetResponse(new AsyncCallback(ResponseReady), request);
    }

    void ResponseReady(IAsyncResult asyncResult)
    {
        HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

        Stream s = response.GetResponseStream();
        StreamReader sr = new StreamReader(s);

        String line = "";
        String Result = "";

        line = sr.ReadLine();
        while (line != null)
        {
            Result += line;
            line = sr.ReadLine();
        }

        s.Close();
    }

The getXML itself is as follows:

public String getXML(bool end)
    {
        StringWriter output = new StringWriterWithEncoding(Encoding.UTF8);
        XmlWriterSettings ws = new XmlWriterSettings();
        ws.Indent = true;
        ws.Encoding = new UTF8Encoding(true);
        ws.ConformanceLevel = ConformanceLevel.Document;

        using (XmlWriter writer = XmlWriter.Create(output, ws))
        {
            writer.WriteStartElement("root");

            if (end)
            {
                writer.WriteAttributeString("testComplete", "true");
            }
            else
            {
                writer.WriteAttributeString("testComplete", "false");
            }

            for (int i = 0; i < theSections.Count(); i++)
            {
                writer.WriteStartElement("section");
                writer.WriteAttributeString("id", theSections.ElementAt(i).Id.ToString());
                writer.WriteAttributeString("title", theSections.ElementAt(i).Name.ToString());
                writer.WriteAttributeString("completed", theSections.ElementAt(i).Completed.ToString());

                for (int j = 0; j < theSections.ElementAt(i).Elements.Count(); j++)
                {
                    writer.WriteStartElement(theSections.ElementAt(i).Elements.ElementAt(j).Name.ToString());

                    for (int a = 0; a < theSections.ElementAt(i).Elements.ElementAt(j).Attributes().Count(); a++)
                    {
                        writer.WriteAttributeString(theSections.ElementAt(i).Elements.ElementAt(j).Attributes().ElementAt(a).Name.ToString(), theSections.ElementAt(i).Elements.ElementAt(j).Attributes().ElementAt(a).Value);
                    }

                    for (int c = 0; c < theSections.ElementAt(i).Elements.ElementAt(j).Elements().Count(); c++)
                    {
                        writer.WriteStartElement(theSections.ElementAt(i).Elements.ElementAt(j).Elements().ElementAt(c).Name.ToString());
                        writer.WriteString(theSections.ElementAt(i).Elements.ElementAt(j).Elements().ElementAt(c).Value);
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }

            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();

        }
        return output.ToString();
    }

(Sorry about the excess amounts of code).

This all works fine, and I can see the xml output. But now I want to add some more code to the getXML() function, and Silverlight just won’t let me do it. Even a simple MessageBox.Show(“something”) won’t display, and the whole method now fails to generate any XML. Having said that, there are no errors or warnings generated within Visual Studio.

I’ve added new code in other areas of the same .cs file and it all works fine, it is just in this one method. I’ve tried rebuilds but also to no avail, so I’m confused as to how this could be the case. Is it a Visual Studio bug?

Thanks in advance for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:41:27+00:00Added an answer on May 17, 2026 at 1:41 am

    I’ve got it working. No ideas why. I think the Cross Thread Error was to do with messageBox being part of the UI, so I removed that and just added in some new xmlwriter stuff… and it worked. I had tried this before and it didn’t work so I’ll keep my eye on it but so far so good. Still puzzled, but nevermind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with following table schema : I have created a method that
I have a factory method that generates django form classes like so: def get_indicator_form(indicator,
I have a method that hash input string to generate MD5 pass from it
I have written an O/R database wrapper that generates some wrapper methods for stored
I have method that returns module path of given class name def findModulePath(path, className):
I'm working with a complicated xml schema, for which I have created a class
I have a class called FileGeneration that extends Activity In FileGeneration I have a
I have a code here that generates XML for Engineer list using linq. My
If I have something like this: static class ManifestGenerator { public static void GenerateManifestFile(){
I'm having trouble grasping generic methods. I have two classes that are generated (they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.