perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » focus » msxml » ask a question » past questions & answers Thursday, 11 October 2007
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services


Go back to list of previously asked questions and answers

Question: Can you please provide a VB example of aborting the parsing while using SAX? I am using MSXML 4.0.
Asked By: Gopi Krishnan
Viewed: 3434
Answer: As per MSXML 4.0 documentation:
The IMXReaderControl interface, which provides the ability to abort, suspend, and resume SAX parsing operations, was implemented for earlier technology preview releases. However, this interface was deemed unready for inclusion in the final release of MSXML 4.0. It has been removed until further notice.
So, if you are using SAXXMLReader40 in your MSXML SAX application, you'll not be able to make use of SAX parsing abort feature. The workaround is to use SAXXMLReader30.

Click here to download a Visual Basic sample application that illustrates using SAXXMLReader30 from the MSXML 4.0 library (as the project adds reference to MSXML 4.0 type library) to abort SAX parsing. Make sure to copy included broadband.xml onto your c:\.

Here is the partial code from the class that implements IVBSAXContentHandler
Implements IVBSAXContentHandler

Public ReaderCtrl As IMXReaderControl

Private Sub IVBSAXContentHandler_startElement(strNamespaceURI As String _
                        , strLocalName As String, strQName As String _
                        , ByVal oAttributes As MSXML2.IVBSAXAttributes)
                        
    If strQName = "Provider" Then
        RateVal = oAttributes.getValueFromQName("Rate")
        NameVal = oAttributes.getValueFromQName("Name")
        
        If CInt(RateVal) < 49 Then
            MsgBox "Found! " & NameVal & " ($" & RateVal & ")"
            ReaderCtrl.abort
        Else
            Debug.Print "Ignoring " & NameVal & " ($" & RateVal & ")"
        End If
    
    End If

End Sub
And here is the main application code that uses above class for parsing: (note we are using SAXXMLReader30 instead of SAXXMLReader40, even though the application adds reference to MSXML 4.0):
Private Sub Form_Load()
    
    Dim ReaderObj As New SAXXMLReader30
    Dim CHImplObj As New ContentHandlerImpl
    
    'Register the Content Handler
    Set ReaderObj.contentHandler = CHImplObj
    
    'Initialize the IMXReaderControl object
    Set CHImplObj.ReaderCtrl = ReaderObj
    
    'Start the parsing
    ReaderObj.parseURL "C:\broadband.xml"

    'End the application
    Unload Me

End Sub

Click here for a C++ example.


Go back to list of previously asked questions and answers
  Contact Us |  | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy