.NET XML and stylesheets

edmicman

Golden Member
May 30, 2001
1,682
0
0
For a project at work I just started getting introduced to XML in .NET via C#. I already had a dataset, and with this article
http://aspnet.4guysfromrolla.com/articles/092403-1.aspx
I was able to basically create an xml file on the fly that is displayed in the browser. I'm not actually saving the file to disk, just creating it on the fly and displaying it.

Well now they want a little nicer interface, and I think I can do that with stylesheets or xlst or something, but I'm not sure where to start. Are there any canned javascript/html things I can use to display the xml in a nice way or something? I don't think I'm searching on the right terms in google or something...any good resources or anything? Thanks!
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Internet Explorer has a default stylesheet for rendering raw XML documents.

Why would you want to display random XML in a browser anyway? Wouldn't you want to use XSL to transform it into something meaningful, like XHTML?
 

edmicman

Golden Member
May 30, 2001
1,682
0
0
Right....originally we had a program that was just parsing a datafile out into a treeview. Well that was buggy and we came across some problems, so they had me parse it out into an XML file instead, which was pretty easy. But they don't like the default IE stylesheet. They want somethign that starts with some fields collapsed, and looks nicer. bah! I think that's what I'm looking for - a way to transform it into some nicer HTML, but I'm not sure where to begin, especially within the confines of .NET. Are there any "starter" XSL files out there or something with some CSS and javascript?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Since you're using ASP.NET, can you use a TreeView control instead?

EDIT: This can be done with XSL, CSS and JavaScript, but I don't know about any generic code out there to handle your specific XML schema.
 

edmicman

Golden Member
May 30, 2001
1,682
0
0
:) we started with the treeview control and abandoned it after it broke on some larger files. Basically we've got some big data files that we are parsing, just to do a sort of quality control thing if something comes up. This project is just to make it look nicer for the user and be more manageable. I think I may have an idea of what I want to do now....back to MSDN!
 

edmicman

Golden Member
May 30, 2001
1,682
0
0
Or, how can I apply an xslt to a dynamic xml I created with an xmltextwriter? Hmmmm, I think I'm in over my head...
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: edmicman
Or, how can I apply an xslt to a dynamic xml I created with an xmltextwriter? Hmmmm, I think I'm in over my head...

Redirect the output to a String object, then load that String object into a DOM Document object. You can apply the XSLT to the DOM object.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Typically you would run the XML through a transform on the server side, and then shoot the transformed document out to the browser. If you aren't familiar with XSLT then you can always use the DOM to parse the XML using ASP on the server side, and construct HTML.

Edit: Mr. Chad's post covers a basic technique for getting the XML run through the DOM. The basic transform pipeline is data->xml->xslt->html->css. It's a lot to jump through if you only want to get a basic view of some simple data up, and don't expect to extend or add to the functionality later. If you do then setting it up this way will be a lot simpler in the long run.
 

vtqanh

Diamond Member
Jan 4, 2001
3,100
0
76
check out Michael Kay's book. I think it's XSLT 2.0 or something like that. Or you can look around the Internet for some basic tutorial on XML Transform using XSLT