XML Parsing in VB6

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 19:13, 6 February 2008 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

As long as the XML conforms to XML Syntax then it is easy enough to parse with a Visual BASIC application.

You can code your own parser or use an existing XML parser. It is recommended that you use a parser that supports the XML Document Object Model (DOM).

Microsoft XML Parser (Msxml.dll)

Microsoft's implementation of the DOM fully supports the W3C standard and has additional features that make it easier for you to work with XML files from your programs. Msxml.dll contains the type library and implementation code via a set of standard COM interfaces.

Set objParser = CreateObject( "Microsoft.XMLDOM" )

If you're working with Visual Basic, you can access the DOM by setting a reference to the MSXML type library, provided in Msxml.dll.

VB6 References: Microsoft XML, version 2.0

Dim xDoc As MSXML.DOMDocument 
Set xDoc = New MSXML.DOMDocument

To load an XML document, create an instance of the DOMDocument class:

Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument
If xDoc.Load("C:\My Documents\cds.xml") Then

Do this if it loads

Else

If it fails to load

End If

Set xDoc = Nothing

ReadyState Properties: State Value

0 = Uninitialized: loading has not started.
1 = Loading: while the load method is executing.
2 = Loaded: load method is complete.
3 = Interactive: enough of the DOM is available for read-only examination and the data has only been partially parsed.
4 = Completed: data is loaded and parsed and available for read/write operations.

loading a file from a URL example:

xDoc.async = False
If xDoc.Load("http://www.develop.com/hp/brianr/cds.xml") Then
  blah blah
Else
  blah blah
End If