Random Tidbits
WinCV.exe (in FrameworkSDK\bin directory) is stand-alone class browser. Other 3rd party tools and shareware do a better job though. Look for
Reflector in or near Chris Sells pages (or his buddies).
XSLT Transformation Output
Start by loading the XPathDocument, then various ways to handle the output of the transformation:
XPathDocument doc = new XPathDocument(Server.MapPath("XML/Customers.xml"));
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("XSLT/Customers.xslt"));
Output with
StringWriter class
StringWriter sw = new StringWriter();
trans.Transform(doc,null,sw);
/*
A StringBuilder class is automatically written to
by the StringWriter class. To get the value in
the StringBuilder you can use the ToString()
method as shown below
*/
this.txtStringBuilder.Text = sw.ToString();
sw.Close();
Output with
XmlTextWriter class
//************ XmlTextWriter XSLT Output Capture
//This can be useful when you need to apply
formatting to the output
StringWriter sw2 = new StringWriter();
//Write to StringWriter
XmlTextWriter xmlWriter = new XmlTextWriter(sw2);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.Indentation = 4;
trans.Transform(doc,null,xmlWriter);
this.txtXmlTextWriter.Text = sw2.ToString();
sw2.Close();
xmlWriter.Close();
Output with
XmlReader class
XmlReader xmlReader = trans.Transform(doc,null);
xmlReader.MoveToContent();
this.txtXmlTextReader.Text =
xmlReader.ReadOuterXml();
xmlReader.Close();
Output with
MemoryStream class
//************ MemoryStream XSLT Output Capture
MemoryStream ms = new MemoryStream();
trans.Transform(doc,null,ms);
//Convert MemoryStream to byte array using
ToArray()
//Convert byte array to a string using the
UTF8Encoding class
UTF8Encoding utf = new UTF8Encoding();
this.txtMemoryStream.Text =
utf.GetString(ms.ToArray());
ms.Close();
Code snipets from
XML and WebServices magazine