Are XML files opened as read-only?

Help
2009-05-13
2012-10-08
  • Debbie Croft
    Debbie Croft
    2009-05-13

    When the Processer and/or XsltTransformer are being used to transform an XML source file, is that source file open as read-only, or is it opened with an exclusive lock for some reason?

    I'm experiencing a problem with an application that uses Saxon that might occur if the Saxon parser opened the source files with exclusive access, but I can't see why it would need to do that.

     
    • Michael Kay
      Michael Kay
      2009-05-13

      Are you on Java or .NET, as a matter of interest? My own experience is that I see this kind of problem more often on .NET - failing to close a file, in particular, seems to cause more problems on .NET.

      As a general point, Saxon doesn't usually open input files. You either do it yourself (by supplying an input stream), or the XML parser does it.

      So the devil here is in the detail. It depends on exactly what you are doing.

       
    • Debbie Croft
      Debbie Croft
      2009-05-13

      I'm using .NET. Here's a code snippet. I don't explicitly open the file (xmlFilePath).

      Uri sourceUri = new Uri(xmlFilePath);
      XdmNode source = f_processor.NewDocumentBuilder().Build(sourceUri);
      
      StringWriter target = new StringWriter();
      Serializer serializer = new Serializer();
      serializer.SetOutputWriter(target);
      
      f_transformer.InitialContextNode = source;
      f_transformer.Run(serializer);
      
      target.Close();
      
       
      • Michael Kay
        Michael Kay
        2009-05-13

        Thanks. In this scenario the URI is converted to a Stream by using the .NET XmlUriResolver class, and the resulting Stream is then passed to a .NET XmlTextReader. I'm afraid those two classes are pretty much black boxes to me. If you want more control you could nominate your own XmlResolver to be used instead, or of course you could use the overloaded Build method that takes a Stream as input.