2

http://www.dreamincode.net/forums/xml.php?showuser=335389

I'd like to save that XML response to a string variable in my class. Is this possible?

namespace SharpDream.Api.Users.Sources
{
    internal class TestSource : IUserInformationSource
    {
        public string GetInformationSource(int forumUserId)
        {
            return @"save things";
        }
    }
}

I seem to remember being able to save string literals, but I do not remember how.

To clarify: I do not want to download the string, I want to copy paste the response to a variable. This concrete implementation is for testing purposes when the internet isn't working or whatnot.

3
  • It sounds like you want to save the string literal as a constant, not a variable. Commented Mar 1, 2011 at 2:00
  • let me get this straight, you don't want to download the content but you want a string literal? Commented Mar 1, 2011 at 2:00
  • @Gabe: I suppose you're right. A constant. :) Commented Mar 1, 2011 at 2:06

2 Answers 2

3

You would need to replace " with "" in the xml. "" represents a " in a verbatim string.

Sign up to request clarification or add additional context in comments.

Comments

2

If I were you, I would download it to an .xml file and then load the XML file when you need to. This would work great for automated unit testing. Sample Code to put into the constructor of your class:

    System.IO.StreamReader file = new System.IO.StreamReader(@"c:\YourXML.xml");
    string test = file.ReadToEnd();

Then refer to the "test" variable for the string itself.

3 Comments

It doesn't really answer my question.
@Sergio - Yes it does answer your question. This is the preferred way to do it. Having it as a literal string is so verbose that it clouds the purpose of the tests.
Just FYI, your question is very confusing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.