Results 1 to 3 of 3

Thread: VB6 - Validating XML with XSD

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    VB6 - Validating XML with XSD

    Does anyone know how I can validate an XML document against an XSD document in VB6?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Public Sub LoadFile(strTargetFile As String)
    2. '***************************************************************************
    3. 'Purpose: Perform actions necessary to load the target xml file
    4. 'Inputs:  strTargetFile - The name of the xml file to be opened.
    5. 'Outputs: None
    6. '***************************************************************************
    7.  
    8.     Dim lngIndex As Long
    9.  
    10.     On Error GoTo ErrorRoutine
    11.    
    12.     XMLdoc.async = False
    13.     XMLdoc.validateOnParse = False
    14.     XMLdoc.preserveWhiteSpace = False
    15.    
    16.     XMLdoc.Load strTargetFile
    17.    
    18.     If XMLdoc.parseError.errorCode = 0 Then
    19.         If XMLdoc.readyState = 4 Then
    20.             ' It's OK
    21.             'AddNodeToTree XMLdoc.documentElement
    22.         End If
    23.     Else
    24.         Err.Description = XMLdoc.parseError.reason & vbCrLf & _
    25.         "Line: " & XMLdoc.parseError.Line & vbCrLf & _
    26.         "XML: " & XMLdoc.parseError.srcText
    27.         Err.Raise 1006
    28.     End If
    29.    
    30.     Exit Sub
    31.    
    32. ErrorRoutine:
    33.  
    34.     ' You would have your own error display here
    35.     'DisplayError "LoadFile"
    36.    
    37. End Sub

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    I should note that this only works with MSXML 4 and newer. Previous versions of MSXML used a Microsoft proprietary version of XSD. Other than that, this code works great - I've used it a couple of times. That's how I found out about the MSXML 4 thing, we were still using 3 at the time and kept getting an error loading the XSD into the schema, even though there wasn't anything wrong with it. Finaly found the answer after scouring MSDN for nearly a week. It was in some obscure text tucked away in tiny print as an "oh, yeah, and by the way...." grrrr.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width