Using XMLTextReader to improve XSLT processing

By reeset / On / In Microsoft, Programming

One of the things that I spend a little too much time working on was how to setup a more streamlined version of resolving entities and ignoring entities.  The key has to do with avoiding a call to the XMLValidateNavigator object, and using the XMLTextReader gives you more granularity over the process.  Here’s an example:

* Function/sub: TransformXSLT
* Description: Does the XSLT translation
* ====================================================*/
public int TransformXSLT(string sSource,
string sDest,
string sXSLT,
bool bRemote)
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(sSource);
if (bRemote==false) {
reader.XmlResolver =
 System.Text.UTF8Encoding Encoding = new System.Text.UTF8Encoding(false);
System.IO.StreamWriter writer =
new System.IO.StreamWriter(sDest, false, Encoding);

  System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument(reader);
    System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform();
    xslt.Transform(doc, null, writer, null);

 } catch (System.Exception eee) {
    this.sXSLTError = eee.ToString();
    return mengine60.ERR_XSLT_ERROR;
return 0;