formatting xml string returned by webservice - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

formatting xml string returned by webservice

Hi.

I've invoked a webserive that returns a string in xml format. I then place the string in a multi line textbox.

what I would like to know is how can I format the string so that the xml tags appear one color and the data inside the tags appears a different color. kind of something like this

[green][/green][blue]London[/blue][green][/green]


thanks in advance

Comments

  • infidelinfidel Posts: 2,900Member
    : Hi.
    :
    : I've invoked a webserive that returns a string in xml format. I then place the string in a multi line textbox.
    :
    : what I would like to know is how can I format the string so that the xml tags appear one color and the data inside the tags appears a different color. kind of something like this
    :
    : [green][/green][blue]London[/blue][green][/green]

    I don't think you can use a regular textbox for that kind of thing. Perhaps a RichTextBox, but then you'd still have to parse out the tags and format them. What about using a WebBrowser control? When you view an XML file in IE, it colors everything similar to how you describe.

    Or perhaps you could use XSLT to transform it into an HTML/CSS page that makes it look pretty?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • airwalkerairwalker Posts: 71Member
    Thanks for that infidel.

    Just one more question. How could I make the xml string returned by the webservice a web browswe object. Would I have to save the xml string as xml file 1st?

    ideally what I want is the data returned by the websercice to be shown as an xml IE page.

    this is the code I currently have that returns that data into a text box

    private void btnGetWeather_Click(object sender, System.EventArgs e)
    {
    net.webservicex.www1.GlobalWeather aw = new net.webservicex.www1.GlobalWeather();

    string s = aw.GetWeather(txtCity.Text, txtCountryName.Text);


    txtResults.Text = s;

    }
  • infidelinfidel Posts: 2,900Member
    : Thanks for that infidel.
    :
    : Just one more question. How could I make the xml string returned by the webservice a web browswe object. Would I have to save the xml string as xml file 1st?
    :
    : ideally what I want is the data returned by the websercice to be shown as an xml IE page.
    :
    : this is the code I currently have that returns that data into a text box
    :
    : private void btnGetWeather_Click(object sender, System.EventArgs e)
    : {
    : net.webservicex.www1.GlobalWeather aw = new net.webservicex.www1.GlobalWeather();
    :
    : string s = aw.GetWeather(txtCity.Text, txtCountryName.Text);
    :
    :
    : txtResults.Text = s;
    :
    : }

    I found this:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=350610&SiteId=1

    Looks like you'll either need to write it to a file and navigate to it, or use some kind of HTML Stream object after transforming the XML.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • airwalkerairwalker Posts: 71Member
    Thanks for your reply.

    I managed to turn the xml string into a web browser object by altering my code as follows

    [code]
    public class InternetWeather : System.Web.UI.Page
    {

    private void Page_Load(object sender, System.EventArgs e)
    {
    net.webservicex.www.GlobalWeather p = new net.webservicex.www.GlobalWeather();

    string s = p.GetWeather("Kingston","Jamaica");

    Response.ContentType = @"text/xml";
    Response.Write(s);

    }
    [/code]


    however, when I run my project now I get this error message which I dont understand:

    [blue]
    The XML page cannot be displayed

    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.

    Switch from current encoding to specified encoding not supported. Error processing resource 'http://localhost/InternetAirpo...

    <?xml version="1.0" encoding="utf-16"?>
    [/blue]

Sign In or Register to comment.