XmlResolver in .NET v1.1

G

George Durzi

In pre v1.1, this is how I would do an Xsl transformation:

System.IO.FileStream fs = new System.IO.FileStream(sFilePath,
System.IO.FileMode.Create);
System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(fs,
System.Text.Encoding.Unicode);
try
{
XmlDataDocument xmlDoc = new XmlDataDocument(SomeDataSet);
System.Xml.Xsl.XslTransform xslTran = new System.Xml.Xsl.XslTransform();
xslTran.Load(XslPathUrl);
xslTran.Transform(xmlDoc, null, xtw);
xtw.Close();
}
catch (Exception ex)
{
xtw.Close();
throw(ex);
}

Now in v1.1 I have to use an XmlResolver. The code below works perfectly,
except, I'm not sure if I'm repeating myself since I have to pass the
XmlResolver in two places. Any thoughts? Is this the right way?

System.IO.FileStream oFileStream = new System.IO.FileStream(sFilePath,
System.IO.FileMode.Create);
System.Xml.XmlTextWriter oXmlTextWriter = new
System.Xml.XmlTextWriter(oFileStream, System.Text.Encoding.Unicode);

try
{
XmlDataDocument oXmlDataDocument = new XmlDataDocument(SomeDataSet);
XslTransform oXslTransform = new XslTransform();

XmlUrlResolver oXmlUrlResolver = new XmlUrlResolver();
oXmlUrlResolver.Credentials = CredentialCache.DefaultCredentials;
Evidence oEvidence = XmlSecureResolver.CreateEvidenceForUrl(XslPathUrl);

oXslTransform.Load(XslPathUrl);
oXslTransform.Transform(oXmlDataDocument, null, oXmlTextWriter,
oXmlUrlResolver);

oXmlTextWriter.Close();
}
catch (System.Exception ex)
{
oXmlTextWriter.Close();
ExceptionManager.Publish(ex);
throw(ex);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top