Alright please bear with me for few posts, I am trying to design a scoreboard application using HTML. The data for scoreboard (including headings and rows and columns) are stored on a server at a remote location. I am trying to develop an ASP.NET script to fetch that XML and convert it into JSON so that I could pick up via jQuery or something else at browser level.

here comes the tough part: I have little experience in C#.NET and have no experience in ASP.NET, I use my scrapings of PHP knowledge and try to find equivalent in ASP.NET.

The first thing I've thought of was to use cURL like alternative to fetch the xml from servers and that didn't go well as there is no cURL equivalent in .NET except to use cURL which I don't want to. I have looked online and found many REST clients examples and have used it in my application which is all good and dandy so far, but the result I'm expecting is not what it's displaying.

This is my code so far

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string scoreboardurl = @"http://www.w3schools.com/xml/cd_catalog.xml";
        Response.Write(HttpGet(scoreboardurl));
    }


    static string HttpGet(string url)
    {
        /** http://stackoverflow.com/a/1605921 **/

        HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
        req.Method = "GET";
        string result = string.Empty;
        using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
        {
            using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }       
        }
        return result;
    }
}

All I want to do is to save these xml elements/nodes so they could be converted to json object
So, can anyone point me in the right direction ?

Recommended Answers

Could use an XMLDocument to store the data from string?

http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx

The above method hopefully should do it.

Jump to Post

How exactly do you wish to manipulate the data?

You can manipulate the xml in the XmlDocument from .loadxml using XSLT.

Shown in: http://stackoverflow.com/questions/2548613/c-sharp-how-to-perform-a-live-xslt-transformation-on-an-in-memory-object

Im presuming you would use XSLT to manipulate the …

Jump to Post

All 5 Replies

no one?

I have changed the fetching code to the following so that I can have greater flexibility over the content I get.

   private HttpWebResponse theresponse;

   public Boolean getmyxml(Uri sourceforxml)
    {
        WebRequest webrequest = WebRequest.Create(sourceforxml);
        HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
        if (webresponse.StatusDescription == "OK")
        {
            theresponse = webresponse;
            return true;
        }
        else
        {
            return false;
        }
    }

isn't there any other way to manipulate the data except for loadxml?

I'm thinking of using a serializer on the data now.

I have searched online and I have found the best way to deal with this is by using XMLSerializers. So, I grabbed my XMLs and created respective XSDs and generated classes from the XSD and mapped the xml with generated XML.

The only problem now is I have to loop again and again for certain elements which is tiresome process.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.