Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

webbrowser control and xml 2

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
hallo,

I am trying to display some xml in a webbrowser control. I found out that the webbrowser has some problems displaying xml. So, I was thinking I could use a xsl and convert the xml to html and then displaying the result in the webbrowser.
The problem is that this xml-xsl --> html conversion is normally done by the webbrowser itself (in fact when I display a xml converted to html in IE and I click "view source" I still see the xml code, and not a html code. This means that the conversion xml-->html is done by the rendering engine of the browser...(?)...I think).

So my question is: is there somewhere a function that really does the job: takes two strings (xml,xsl) and gives a html string?

Thanks for suggestions

 
I found out that the webbrowser has some problems displaying xml.
what problems specifically? We need to know this before we can go any further.

in fact when I display a xml converted to html in IE and I click "view source" I still see the xml code
html is just a specification of xml. The same was RSS is a specification of xml.

is there somewhere a function that really does the job: takes two strings (xml,xsl) and gives a html string?
xml is the data, xsl is the format. there is no way to automajically convert xml to html without xsl.

what code do you currently have in place?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Specific problem:
Actually I dont't what the problem is: bad answer, I know, but I know how the problem behaves. The situation: I build (programmatically) a xml string and I assign it to the webbrowser.documenttext property. The xml string that I buil contains a reference (with absolute path) to an existing xsl file. What happens is that the webbrowser control displays the xml without any formatting. More: if I click "view source" and I copy the code and I paste it a new xml file and then I open this file with IE it displays correctly.
So I don't know... it seems that webbrowser control doesnt support xml rendering.

there is no way to automajically convert xml to html without xsl
maybe I wasn't clear: I am looking for a function that takes two arguments: an xml string(or file) AND a xsl string(or file), and then it gives as output a html string(or file)






 
I build (programmatically) a xml string and I assign it to the webbrowser.documenttext property.
this might be the problem. if your use the webrequest object you need to write the xml string to the outputstream. it should be automatic after that. if not you will need to set the content type/headers. no need for xsl.

maybe I wasn't clear: I am looking for a function that takes two arguments: an xml string(or file) AND a xsl string(or file), and then it gives as output a html string(or file)
any object would just output a string. the html would be defined in your xsl.

Check out System.XML or System.Text.Xml namespace there are objects in there that can transform xml into formatted text.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
here again,

I found out. Thanks for the hint. Actually yes, everything needed is in the system.xml.

Here some code for people who might need: _xsl, _xml and _html are strings.

Code:
            XslCompiledTransform transform = new XslCompiledTransform();
            transform.Load(XmlReader.Create(new StringReader(_xsl)));
            XmlReader xr = XmlReader.Create(new StringReader(_xml));
            StringBuilder htmlContent = new StringBuilder();
            XmlWriter result = XmlWriter.Create(htmlContent);
            transform.Transform(xr, result);
            _html = (htmlContent.ToString());
 
Hello karerda,

Thanks for taking the time to post your code! I have been looking all over for examples of how to apply an Xsl transformation programmatically.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top