xsl-list
[Top] [All Lists]

RE: [xsl] Saxon Process is not releasing my output file

2006-12-11 10:23:43
The best place to report product-specific problems is on the appropriate
list for that product; in the case of Saxon, that's the saxon-help mailing
list or forum on the SourceForge.net site.

You're right, when you use the DocumentBuilder.Build(Uri) method in the .NET
API, it fails to close the input stream obtained from the Uri. Workaround:
change your call Build(Uri) to use:

            DocumentBuilder.BaseUri = uri;
            Stream inn = (Stream)DocumentBuilder.XmlResolver.GetEntity(
                         uri, "application/xml",
Type.GetType("System.IO.Stream")
            XdmNode input = Build(inn);
            inn.Close(); 

Pardon my lack of VB.NET syntax.

Michael Kay
http://www.saxonica.com/



-----Original Message-----
From: Spencer Tickner [mailto:spencertickner(_at_)gmail(_dot_)com] 
Sent: 10 December 2006 17:33
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Saxon Process is not releasing my output file

Hi List,

Hope this is an "in Scope" question. I'm using Saxon to run a 
process in .net. The basic scenario is my xslt takes an XML 
called new, compares it to an XML document called old. Then 
the "new" XML document is copied over "old".

The problem is when the copy happens I get the dreaded "The 
process cannot access the file 'L:\file_path\old.xml' because 
it is being used by another process".

The call:

Dim x As New Saxon
x.Transform(strDir & "my.xsl", strDir & "new.xml", strRepository &
"difference.xml")
x = Nothing

' Error occurs here
File.Copy(strDir & "Stat.xml", strDir & "stat_old.xml", True)


The Transform: (probably more Nothing/Flush/Close commands 
then I need but I wanted to make sure everything was taken care of):

       Public Sub Transform(ByVal xslDoc As String, ByVal 
xmlDoc As String, _
            ByVal output As String)


            Dim u As Uri
            'Create a New Processor instance
            Dim processor As New Processor
            'Load the source document
            u = New Uri(xmlDoc)
            Dim input As XdmNode = 
processor.NewDocumentBuilder.Build(u)
            'Create the transformer for the stylesheet
            Dim transformer As XsltTransformer

            Try
                u = New Uri(xslDoc)

                transformer = _
                    processor.NewXsltCompiler().Compile(u).Load()
            Catch ex As Exception
                u = Nothing
                MsgBox("Exception" & ex.ToString)
                MsgBox(ex.StackTrace)
                Throw New Exception(ex.Message)
            End Try

            'Set the root node of the source document to be 
the initial context node
            transformer.InitialContextNode = input

            'Create the serializer
            Dim serializer As New Serializer
            Dim fi As FileStream
            Try
                fi = New FileStream(output, FileMode.Create, 
FileAccess.Write)
                serializer.SetOutputStream(fi)
                'Transform the source XML
                transformer.Run(serializer)
                'fi.Flush()
                'fi.Dispose()
                fi.Close()
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                u = Nothing
                serializer = Nothing
                transformer = Nothing
                processor = Nothing
                input = Nothing
                fi = Nothing
            End Try

        End Sub

Thanks for any help..

Spencer

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>