开发者

How can I save the this XML to a C# string variable?

开发者 https://www.devze.com 2023-02-13 21:00 出处:网络
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?

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 respo开发者_StackOverflow社区nse to a variable. This concrete implementation is for testing purposes when the internet isn't working or whatnot.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消