Designing Your Own Reporting Service: A Web Service to Convert XML to HTML Using XSL - Developing the XML Web Service continued
(Page 3 of 7 )
Now, let us proceed with the “GenerateHTMLString” method, which is usually called by “BuildHTMLString”.
private string GenerateHTMLString(string sXMLSource)
{
// Create the XslTransform.
XslTransform xslt = new XslTransform();
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials =
System.Net.CredentialCache.DefaultCredentials;
// Load the stylesheet.
string sXSLLocation = GetXSLLocation();
xslt.Load( sXSLLocation );
// Load the XML string.
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.XmlResolver = resolver;
xmlDoc.LoadXml(sXMLSource);
// Create the Stream to place the output.
Stream stream = new MemoryStream();
// Transform the file.
xslt.Transform(xmlDoc, null, stream, resolver);
// Remember to Flush the Stream and set the position to
0
stream.Flush();
stream.Position = 0;
// Create a StreamReader to Read the Stream and Return
the String
System.IO.StreamReader sr = new System.IO.StreamReader
(stream);
return sr.ReadToEnd();
}
And thus, our coding (development) part is successfully finished. The next section helps you to build the solution and test it from within Visual Studio.NET IDE to your own satisfaction.
Next: Defining the XSLT >>
More XML Articles
More By Jagadish Chaterjee