Link to home
Start Free TrialLog in
Avatar of dtomyn
dtomyn

asked on

VB 6 and SAX (reading an XML file being used by the DOM)

I would like to create a systray application which will show the current status of an application.  The idea is that I will determine the status of a batch process by reading its corresponding XML log file.  The log file looks like this:
<log>
      <RunGroup logDate="2004/07/30 12:13:43 PM">
            <TaskGroup logDate="2004/07/30 12:13:43 PM" name="Backup XPS Directory">
                  <method logDate="2004/07/30 12:13:43 PM" name="zip" status="success">
                  </method>
                  <method logDate="2004/07/30 12:13:44 PM" name="copy" status="success">
                  </method>
            </TaskGroup>
      </RunGroup>
      <RunGroup logDate="2004/07/30 12:13:53 PM">
            <TaskGroup logDate="2004/07/30 12:13:53 PM" name="Backup XPS Directory">
                  <method logDate="2004/07/30 12:13:53 PM" name="zip" status="success">
                  </method>
                  <method logDate="2004/07/30 12:13:54 PM" name="copy" status="failed">
                  </method>
            </TaskGroup>
      </RunGroup>
</log>
The application creating this log file is doing so via the MSXML DOM (version 4).

When I attempt to access the file also using the DOM while the other process is writing to it I get an error stating that I cannot access it since another process is using it.
I am assuming that this is because the DOM can be used to write to the file as well.  However, in my case I only want to read from the file.
So, I am assuming that I have to use SAX to do this, but just can't get a grasp on how to do this.  I have read numerous Microsoft articles but still am not sure.

So, can anyone provide code to extract from the above the last status?  From the above it would be "failed".  Also, am I correct in saying that SAX will be able to access the file while the DOM still has a hold of it?  If this is incorrect, is there a way to actually do this?
Thanks
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

It would be no different with SAX.  You are going to have to retry until it has quit writing the Xml document.
Avatar of dtomyn
dtomyn

ASKER

Is SAX not like a read only recorset though?  Can you think of any other alternative (than to keep retrying)?   Hmmm... I suppose if the file is locked I can assume that the other process is working though... I was hoping to be able to display the method though in the tooltip.
>>Is SAX not like a read only recorset though? <<
In a sense, yes.  Although strictly speaking it is more like a firehose (forward-only, read-only) resultset.  But to continue your analogy, you cannot open (not even) a read-only recordset if the database is opened exclusively.  I suspect what is happening is that while it is writing the file is locked.  However, this has to be only very briefly, so a retry after one second should suffice.
Avatar of dtomyn

ASKER

Would you be able to post some code to read the last status attribute given the XML above (using SAX... my current method is using the DOM)?  Just for completeness I would like to try this.
Sorry cannot help you there, I have never used it.  Hopefully someone else can step up to the plate.
ASKER CERTIFIED SOLUTION
Avatar of aParser
aParser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial