Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I need to convert dataset to html...quickly???

Posted on 2006-07-20
7
Medium Priority
?
767 Views
Last Modified: 2008-02-01
I need to convert data inside a dataset dynamically, hopefully using the WriteXml method, then converting in 1 line of code to html....can this be done???
I am expecting to be able to do something like document.XmlToHtml();
Is there already some functionality microsoft has thought of, instead of doing a foreach row loop through my table ...write("<TD>"+col1+</TD>"); etc...

Is it also possible to use this same train of thought to try to copy & paste the
html inside a word document for preview?

Thanks in advance
0
Comment
Question by:hesaigo999ca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:topdog770
ID: 17148946
Not sure if this helps, or does exactly what you are wanting...

http://www.csharphelp.com/archives/archive78.html
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 1000 total points
ID: 17148987

Yes, this can be done.

A dataset can convert all of its data to XML

    DataSet ds = new DataSet();
    // load data
    ds.GetXml();


Your resulting XML will look something like:

<Table1>
      <Col1>data1</Col1>
      <Col2>data1</Col2>
      <Col3>data1</Col3>
      <Col1>data2</Col1>
      <Col2>data2</Col2>
      <Col3>data2</Col3>
      <Col1>data3</Col1>
      <Col2>data3</Col2>
      <Col3>data3</Col3>
</Table1>

From here you can apply an XML style sheet (XLS) and perform an XML style transformation (XSLT).

Assuming you have the template already written and loaded into memory, applying this stylesheet will consist of just one line of code.


here are som good sites for XSLT
[tutorial]
http://www.zvon.org/xxl/XSLTutorial/Output/index.html

[reference]
http://www.zvon.org/xxl/XSLTreference/Output/index.html


The learning curve can be pretty steep.  But once you know it, you'll find uses for it *everywhere*.
0
 

Author Comment

by:hesaigo999ca
ID: 17149197
I was hoping to avoid using the xslt as these would have to be also installed on the clients machine, is there not a way of being able to do something like

dataTable.WriteXml("nameOfFile",WriteXmlMode.WriteSchema); //this is with all my data

then open the xml file as follows

XmlDocument xmll = new XmlDocument("nameOfFile");
string tmp = xmll.ToHtml(); ???
Word.Document wdoc = new WordDocument();
wDoc.Paste(tmp);
...this is not accurate, just a quick explanation of what I would like to do...

Am I missing something about microsoft not providing enough of this type of functionality?
I am aware of using the xsl files to declare a format, but I have multi reports to display, and to have multi xsl files instead of using what I already have in code....
(i am using right now a foreach row in datatable which is pretty much the same as the xsl
<xsl:for-each select="table/row"> ...so I would not be really gaining anything
unless the time was well worth it programmatically speaking of course...
else I might as well just use what I have


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:hesaigo999ca
ID: 17149262
I would just like to know what is faster, the treatment using the xml,xsl parser in c#
or actually just doing it programmatically in c# by going through each
column and inserting string tmp += "<TD>"+col+"</TD>" in a for loop

0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17149565

Using the XML/XSL parser is probably faster, although you could come pretty close to the performance if you use a string builder object instead of string += string + "string".

StringBuilder sb = new StringBuilder();
sb.Append("<TD>");
sb.Append(col);
sb.Append("</TD>");


In either case, you are talking about saving milliseconds.  Not really all that impressive.  I would encourage using XSLT because it is more extensible and it is quickly becoming the defacto standard.  
0
 

Author Comment

by:hesaigo999ca
ID: 17153216
sounds ok to me, but I have one last concern, being that I am going to use xsl templates, then is there a way I could use these templates dynamically without having to create the files, sort of like build a string tmp = "xsl code goes here" and use the string to be parsed as xsl
on the fly.... xmll.Schemas.Add( new XmlSchema(tmp)); or something like this?

This way I would be able to create the schemas based on dynaimcally templated xsl formats...
and could change them per client needs...

please show me some code if possible, or links thanks...
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17154247

Yes, you can... but that kind of defeats the point.  I understand not wanting a ton of support files on your client machines, but the point of using XSL is to not have to re-code or compile your dlls everytime you want to make a minor change to the output.

0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question