Project

Profile

Help

SaxonCS: XmlReaderResource holds an XmlReader which implements IDisposable; shouldn't XmlReaderResource implement IDisposable as well?

Added by Martin Honnen 10 months ago

Trying to figure out how to use SaxonCS and Norm's C# Resolver to load XSLT or XML from an embedded resource I wrote some code that uses XmlReaderResource:


Resolver resolver = new Resolver();

XmlReaderSettings settings = new XmlReaderSettings();
settings.Async = false;
settings.XmlResolver = resolver;

var xsltCompiler = saxon.NewXsltCompiler();

xsltCompiler.StylesheetModuleResolver = req =>
{
    var xmlResourceReader = XmlReader.Create(req.Uri.AbsoluteUri, settings);
    return new XmlReaderResource(docBuilder, xmlResourceReader);
};


var xml3ResourceUri = UriUtils.GetLocationUri("XmlResolverTest2/samples/XMLFile3.xml", Assembly.GetExecutingAssembly());

var xsltExecutable = xsltCompiler.Compile(xml3ResourceUri);

Now XmlReader implements IDisposable and is therefore normally wrapped into some using but I don't see how I could do that with the lambda assigned to xsltCompiler.StylesheetModuleResolver; therefore I wonder whether XmlReaderResource shouldn't implement IDisposable to be usable itself with a using and then dispose of its used XmlReader.

Any thoughts?


Replies (3)

Please register to reply

RE: SaxonCS: XmlReaderResource holds an XmlReader which implements IDisposable; shouldn't XmlReaderResource implement IDisposable as well? - Added by Martin Honnen 10 months ago

The XmlReaderResource source code seems to be (for 12.1, the 12.2 branch doesn't (yet?) seem to be online) at https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_1/entry/src/main/saxon-cs/engine/Saxon/Api/XmlReaderResource.cs.

Still wondering whether any XmlReaders passed in/created in the StylesheetModuleResolver need to be disposed of properly.

RE: SaxonCS: XmlReaderResource holds an XmlReader which implements IDisposable; shouldn't XmlReaderResource implement IDisposable as well? - Added by Norm Tovey-Walsh 10 months ago

The XmlReaderResource source code seems to be (for 12.1, the 12.2
branch doesn't (yet?) seem

No, on my list for tomorrow. Or Monday. Or Tuesday. Soon.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: SaxonCS: XmlReaderResource holds an XmlReader which implements IDisposable; shouldn't XmlReaderResource implement IDisposable as well? - Added by Norm Tovey-Walsh 10 months ago

Saxonica Developer Community writes:

The XmlReaderResource source code seems to be (for 12.1, the 12.2
branch doesn't (yet?) seem to be online) at
https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_1/entry/src/main/saxon-cs/engine/Saxon/Api/XmlReaderResource.cs.

I’ve pushed the latest 12.2 commits to the mirror repositories.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

    (1-3/3)

    Please register to reply