I need to write an error log to a XML file using Visual Basic 6.0. Is there an easy way to do this?
The error log will contain the error number, source, desc, and a timestamp.
Thanks, Jeff
I need to write an error log to a XML file using Visual Basic 6.0. Is there an easy way to do this?
The error log will contain the error number, source, desc, and a timestamp.
Thanks, Jeff
Probably it's best to use Microsoft's MSXML libraries to do that.
There is a sample in the knowledge base: http://support.microsoft.com/kb/286817
The Microsoft MSXML libraries are your first port of call, but there are things you need to consider before you decide to use it.
Appending error messages to an Xml using the MSML library will parse and load the Xml file every time you open it. As the Xml file grows you will find your app slows to a crawl.
It would be good if you could "just" append your error to the end of the file, however because of closing tags, this isn't straightforword, but it can be done.
If you have control over how the Xml file is created, you can work around this performance bottle next by splitting the Xml file into two, one with the header and one with the body of the xml. Then you can append to the end of the body file (by using an Xml writer class, or by simply appending text to the file).
See Efficient Techniques for Modifying Large XML Files for more info
However all this is unnecessarry if you're writing one error to the xml file, and the next error goes into another Xml file. In that case, go with MSXML
Hope this helps.