We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it possible to convert an XML document to HTML using XSLT and how can I print the document in a console?

 

Yes. It is possible to convert the xml document to htm using XSLT and can be easily printed in a console application.

Here is the code to convert the xml document to htm file.

Note: This code has to be placed in try catch block.

C#

HTMLUIControl htmlu=new HTMLUIControl();

XPathDocument myXPathDocument = new XPathDocument("..//..//Albums.xml");

XslTransform myXslTransform = new XslTransform();

XmlTextWriter writer = new XmlTextWriter("result.htm", null);

myXslTransform.Load("..\\..\\HhRunSheet.xslt");

myXslTransform.Transform(myXPathDocument, null, writer);

writer.Close();

StreamReader stream = new StreamReader ("result.htm");

Console.Write("**This is result document**\n\n");

Console.Write(stream.ReadToEnd());

VB

Dim myXPathDocument As XPathDocument = New XPathDocument("..//..//RunSheetXml_02_Albums.xml")

Dim myXslTransform As XslTransform = New XslTransform()

Dim writer As XmlTextWriter = New XmlTextWriter("result.htm", Nothing)

myXslTransform.Load("..\..\HhRunSheet.xslt")

myXslTransform.Transform(myXPathDocument, Nothing, writer)

writer.Close()

Dim stream As StreamReader = New StreamReader ("result.htm")

Console.Write("**This is result document**" & Constants.vbLf + Constants.vbLf)

Console.Write(stream.ReadToEnd())

Here is the code to print the generated htm file using the printer.

C#

htmlu.LoadHTML("result.htm");

InputHTML document = new InputHTML( "result.htm", htmlu.FormatManager );

htmlu.PrepareDocument(document, true);

//loading the generated htm file in HTMLUI control.

htmlu.LoadHTML("result.htm");

htmlu.AutoScrollMinSize = document.AutoScrollMinSize;

HTMLUIPrintDocument pd;

pd=new HTMLUIPrintDocument(htmlu.Document);

PrintDialog dg = new PrintDialog();

dg.Document = pd;

dg.AllowSomePages = true;

//To print all the pages in document.

dg.PrinterSettings.PrintRange=System.Drawing.Printing.PrintRange.AllPages;

pd.Print();

VB

htmlu.LoadHTML("result.htm")

Dim document As InputHTML = New InputHTML("result.htm", htmlu.FormatManager)

htmlu.PrepareDocument(document, True)

htmlu.LoadHTML("result.htm")

htmlu.AutoScrollMinSize = document.AutoScrollMinSize

Dim pd As HTMLUIPrintDocument

pd = New HTMLUIPrintDocument(htmlu.Document)

Dim dg As PrintDialog = New PrintDialog()

dg.Document = pd

dg.AllowSomePages = True

dg.PrinterSettings.PrintRange=System.Drawing.Printing.PrintRange.AllPages

pd.Print()

Article ID: Published Date: Last Revised Date: Platform: Control:
825 04/30/2011 07/10/2014 Windows Forms HTMLUIControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon