Parse error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Abhinay
    New Member
    • Jul 2006
    • 44

    Parse error

    hi,

    I wrote function to validate my xml file against specified schema, it works fine in most of the cases, but some times validation failed because following parse Error.

    The process cannot access the file because it is being used by another process.

    can any budy help me, to find out its unexpected behaviours or I missed somthing in my code.
    I have close file pointer before validation process. If i missed somthing in my code then it has to failed every time, but this is not the case.
    Please sagest me.

    I am using C++ on windows.


    Code:

    //clientNamespace = Client namespace
    // fullSchemaFileN ame = Schema file path
    // strDataFileName = XML file path
    [HTML]
    MSXML2::IXMLDOM Document2Ptr docMainXML;
    MSXML2::IXMLDOM SchemaCollectio n2Ptr schemaCache;


    docMainXML.Crea teInstance(__uu idof(MSXML2::Fr eeThreadedDOMDo cument40)
    schemaCache.Cre ateInstance(__u uidof(MSXML2::X MLSchemaCache40 ))

    docMainXML->async=false;

    schemaCache->add(_bstr_t(cl ientNamespace.c _str()),_varian t_t(fullSchemaF ileName.c_str() ));

    docMainXML->schemas = _variant_t((MSX ML2::IXMLDOMSch emaCollection2P tr)schemaCache, true);

    VARIANT_BOOL isValidated = docMainXML->load(strDataFi leName.c_str()) ;
    if(isValidated == FALSE)
    {
    MSXML2::IXMLDOM ParseErrorPtr p = docMainXML->parseError;
    throw XMLDocumentExce ption(cs("Reaso n:%s Line:%ld",(cons t char*)p->reason,p->line),_QL_);
    }[/HTML]

    Thank you
    Abhinay
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    If you have multiple processes using the same file, you need to set up a mutex. A lock so that you know who is using the file.

    One simple way is to use a lock file. If the lock file opens OK, then someone is using the data file. If it doesn't open, then you create it. Then you can use thwe data file. When you are finished, delete the lock file.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Are you running multiple instances of your program at the same time? If so, then these instances will contend for access to the input file.

      Is your input file being used by some other program (editor, browser, etc) while you run your program? If so, close out the other program before you run yours.

      Comment

      • Abhinay
        New Member
        • Jul 2006
        • 44

        #4
        Originally posted by donbock
        Are you running multiple instances of your program at the same time? If so, then these instances will contend for access to the input file.

        Is your input file being used by some other program (editor, browser, etc) while you run your program? If so, close out the other program before you run yours.
        My aplication is multi threaded daemon process, one thread for one client and each client have its own xml file, no chance of sharing input xml file.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          If your xml input file is not being shared, is the schema being shared?


          There is something going that hasn't come up yet.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Originally posted by Abhinay
            I wrote function to validate my xml file against specified schema, it works fine in most of the cases, but some times validation failed because following parse Error.

            The process cannot access the file because it is being used by another process.
            Can you instrument your code so that it identifies which file provoked the error message?

            Comment

            Working...