This demo uses SAX to write an XML document in a custom format.
Even though an ADO Recordset.Save method can write XML output to disk, this uses a proprietary serialization schema your program has no control over. Sometimes you want a more compact or just a more specific output format. Sometimes you don't want to write to disk.
People who learned VB6 from copy/pasting Classic ASP VBScript snippets tend to be familiar with MSXML's DOM to some extent. However in large data scenarios or when performance and control are important using a SAX ("Simple API for XML") approach can be a handy alternative. MSXML also contains Microsoft's SAX2 implementation in addition to DOM and other objects.
Demo
There are two programs provided in VB6 source code form: CreateMDB and ExtractXML. There is also some sample data provided in CSV format.
CreateDB is used to create an empty Jet 4.0 database and import supplied CSV data into it. If you try running this with some locale settings you may have trouble (for example the data contains decimal points as periods, and the commas are commas). However there is an included schema.ini file that may overcome this for you.
![Name: sshot1.png
Views: 4
Size: 1.5 KB]()
ExtractXML performs a query against the tables in the previously-created Movies.mdb and exports this as XML via SAX as an Exported.xml file.
![Name: sshot2.png
Views: 4
Size: 1.8 KB]()
Result:
Requirements
VB6 on a version of Windows that includes MSXML 6.0.
You could easily change the MSXML Library reference to MSXML 3.0 and adjust the data types to match (look for "60" suffixes and change them to "30" suffixes). That can help on unsupported downlevel OSs like Windows XP or even Windows 95 with IE 5.x installed.
Summary
While there is nothing spectacular about this, it shows a way to quickly export large rowsets from a database query in custom XML formats. It also serves as a demonstration of one use of the SAX2 portion of MSXML.
The attachment is large, but this is mainly due to the included sample data. See the ReadMe.txt file it contains.
Even though an ADO Recordset.Save method can write XML output to disk, this uses a proprietary serialization schema your program has no control over. Sometimes you want a more compact or just a more specific output format. Sometimes you don't want to write to disk.
People who learned VB6 from copy/pasting Classic ASP VBScript snippets tend to be familiar with MSXML's DOM to some extent. However in large data scenarios or when performance and control are important using a SAX ("Simple API for XML") approach can be a handy alternative. MSXML also contains Microsoft's SAX2 implementation in addition to DOM and other objects.
Demo
There are two programs provided in VB6 source code form: CreateMDB and ExtractXML. There is also some sample data provided in CSV format.
CreateDB is used to create an empty Jet 4.0 database and import supplied CSV data into it. If you try running this with some locale settings you may have trouble (for example the data contains decimal points as periods, and the commas are commas). However there is an included schema.ini file that may overcome this for you.
ExtractXML performs a query against the tables in the previously-created Movies.mdb and exports this as XML via SAX as an Exported.xml file.
Result:
Code:
<ratings>
<movie average="5.0" min="5.0" max="5.0">10 Attitudes (2001)</movie>
<movie average="5.0" min="5.0" max="5.0">16 Wishes (2010)</movie>
<movie average="5.0" min="5.0" max="5.0">29th and Gay (2005)</movie>
:
:
<movie average="2.5" min="2.5" max="2.5">Zoom (2006)</movie>
</ratings>
Requirements
VB6 on a version of Windows that includes MSXML 6.0.
You could easily change the MSXML Library reference to MSXML 3.0 and adjust the data types to match (look for "60" suffixes and change them to "30" suffixes). That can help on unsupported downlevel OSs like Windows XP or even Windows 95 with IE 5.x installed.
Summary
While there is nothing spectacular about this, it shows a way to quickly export large rowsets from a database query in custom XML formats. It also serves as a demonstration of one use of the SAX2 portion of MSXML.
The attachment is large, but this is mainly due to the included sample data. See the ReadMe.txt file it contains.