/// Author: Francis A. Shanahan
/// http://www.FrancisShanahan.com
using System;
using System.Xml;
using System.Net;
using System.IO;
using System.Text;
using System.Configuration;
using System.Xml.Xsl;
using System.Collections.Specialized;
///
/// Simply Helper class with many useful Mashup functions
///
public static class webUtility
{
static webUtility()
{
}
///
/// Transforms an xml document using an XSL style sheet
///
/// the XML to tranform
/// The filename of the XSL file to use
/// The transformed document as a string
public static string DoXSLTransformation(XmlDocument myDoc, string strXsl)
{
// Create an XSL transformation
XslCompiledTransform myProcessor = new XslCompiledTransform();
// Load the XSL document
myProcessor.Load(System.Web.HttpContext.Current.Server.MapPath(strXsl));
// Create a text writer for use in the transformation
StringWriter myWriter = new StringWriter();
// Transform the source XML document
myProcessor.Transform(myDoc, (XsltArgumentList)null, myWriter);
// Return the result as a string
return myWriter.ToString();
}
///
/// Retrieves a Uri using HTTP GET and returns the results as XML
///
/// Uri to retrive
/// Xml document results
public static XmlDocument GetUri(string strURI)
{
// Create a request object
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strURI);
// Obtain the response from the server
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream myResponseStream = myResponse.GetResponseStream();
// Load the result into an XML document
XmlDocument myDoc = new XmlDocument();
myDoc.Load(myResponseStream);
// return the XML document
return myDoc;
}
}