Visual Basic Code (inline.frm)
This topic provides Visual Basic code.
Try It!
Copy the first XML/XSD data file from the resource files, and paste it into a text file. Save the file as valid.xml.
Copy the second XML/XSD data file from the resource files, and paste it into a text file. Save the file as notValid.xml, in the same directory where you saved valid.xml.
Create a Standard EXE project in Visual Basic. Save the empty project as inline.vbp to the same directory you used in previous steps. Name and save the form file as inline.frm.
Create a reference to MSXML 6.0. To do this, select References... from the Project menu, and then check the box for Microsoft XML, v6.0.
Double click on the TextBox icon from the tools menu. A TextBox control will appear on the project's form named Text1. In the properties for Text1, set the ScrollBars property to use "2 - Vertical" as the value and set the MultiLine property to True.
Copy the Visual Basic code listing above, and paste it into the Visual Basic code editor to replace whatever code is already there.
Execute the code by selecting Start from the Run menu.
Verify that your output is the same as that listed in the output for this example. You can either maximize or resize the form to better view the output.
inline.frm
Private Sub Form_Resize()
' Resize text box to size of form.
Text1.Width = Form1.Width - 350
Text1.Height = Form1.Height - 750
End Sub
Private Sub Form_Load()
' Resize text box to size of form.
Text1.Top = 100
Text1.Left = 100
Text1.Width = Form1.Width - 350
Text1.Height = Form1.Height - 750
' Validate files and display output in text box.
Dim sOutput As String
sOutput = ValidateFile("valid.xml")
sOutput = sOutput & ValidateFile("notValid.xml")
Text1 = sOutput
End Sub
Function ValidateFile(strFile As String)
' Create an XML DOMDocument object.
Dim x As New DOMDocument60
' Load and validate the specified file into the DOM.
x.async = False
x.validateOnParse = True
x.resolveExternals = True
x.setProperty "UseInlineSchema", True
x.Load App.Path & "\" & strFile
' Return validation results in message to the user.
If x.parseError.errorCode <> 0 Then
ValidateFile = "Validation failed on " & _
strFile & vbCrLf & _
"=====================" & vbCrLf & _
"Reason: " & x.parseError.reason & _
vbCrLf & "Source: " & _
x.parseError.srcText & _
vbCrLf & "Line: " & _
x.parseError.Line & vbCrLf
Else
ValidateFile = "Validation succeeded for " & _
strFile & vbCrLf & _
"======================" & _
vbCrLf & x.xml & vbCrLf
End If
End Function