Advertisement

06.06.2008 at 08:33AM PDT, ID: 23464091
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Validating XML with XSD using MSXML2.DOMDocument in vb6

Asked by gazzacrowe in Extensible Markup Language (XML), VB Objects

Tags: , , ,

Hi.
I have a VB6 function that takes an XML file and an XSD file as input parameters, (see code below: source:- http://www.nonhostile.com/howto-validate-xml-xsd-in-vb6.asp).

The function validates the XML file using the XSD and returns a string detailing the first error found, ("" means the file has passed XSD validation).

The trouble with this is that the XSD validation only returns details of the first validation error.
What I really want to end up with is a string detailing all errrors found.
e.g.
For a file with 2 validation errors, I would like the function to return a string something like this:

Error parsing '2008-13-07' as date datatype.
The element: '{urn:iso:std:iso:20022:tech:xsd:pacs.008.001.01}IntrBkSttlmDt' has an invalid value according to its data type.
Error parsing '2360.0q' as decimal datatype.
The element: '{urn:iso:std:iso:20022:tech:xsd:pacs.008.001.01}IntrBkSttlmAmt' has an invalid value according to its data type.

Can anyone suggest a way of doing this?
NOTE I am restricted to using VB6 & cannot add any new project references, (hence the late binding in the code below).

Thanks in advance.
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
Public Function ValidateXML(ByVal sXMLPath As String, ByVal sXSDPath As String) As String
Dim sNamespace As String
Dim objSchemas As Object
Dim oXML As Object
Dim oXSD As Object
Dim oErr As Object
    
    On Error Resume Next
    ValidateXML = ""
    
    'Load XSD as DOM to populate in Schema Cache
    Set oXSD = CreateObject("MSXML2.DOMDocument.4.0")
    If Err.number <> 0 Then
        ValidateXML = "Fail - ActiveX Component Load failure"
        Exit Function
    End If
    oXSD.async = False
    If Not oXSD.Load(sXSDPath) Then
        ValidateXML = "Fail - XSD Load failure"
        Exit Function
    Else
        'Get namespace name from XSD TargetNamespace attribute
        sNamespace = oXSD.documentElement.getAttribute("targetNamespace")
    End If
   
    'Populate schema cache
    Set objSchemas = CreateObject("MSXML2.XMLSchemaCache.4.0")
    If Err.number <> 0 Then
        ValidateXML = "Fail - ActiveX Component Load failure"
        Exit Function
    End If
    objSchemas.Add sNamespace, oXSD
   
    'Load XML file (without validation - that comes later)
    Set oXML = CreateObject("MSXML2.DOMDocument.4.0")
    If Err.number <> 0 Then
        ValidateXML = "Fail - ActiveX Component Load failure"
        Exit Function
    End If
    oXML.async = False
    oXML.validateOnParse = False
    oXML.resolveExternals = False
   
    'Load XML, without any validation
    If Not oXML.Load(sXMLPath) Then
        ValidateXML = "Fail - XML Load failure"
        Exit Function
    End If
   
    'Bind Schema Cache to DOM
    Set oXML.schemas = objSchemas
   
    'Does this XML measure up?
    Set oErr = oXML.Validate()
 
    If oErr.errorCode <> 0 Then
        ValidateXML = "Fail - " & oErr.reason
    Else
        ValidateXML = ""
    End If
End Function
 
Loading Advertisement...
 
[+][-]06.06.2008 at 09:05AM PDT, ID: 21730320

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.06.2008 at 09:48AM PDT, ID: 21730692

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.06.2008 at 01:47PM PDT, ID: 21732563

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.06.2008 at 01:48PM PDT, ID: 21732566

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.06.2008 at 02:00PM PDT, ID: 21732659

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), VB Objects
Tags: Microsoft, Visual Basic, vb6, vb6
Sign Up Now!
Solution Provided By: jeffld
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628