Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 3rd, 2005, 08:01 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validating Xml files with XSD file

Hi,

After selecting the folder which contains xml files gets validate and display errors in RichTextBox.
Here it showing error from one xml file, but there is one more xml file which contains error.
How would I display error from multiple xml files in richtextbox.

Private Sub btnFolderXMLFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFolderXMLFiles.Click
        Dim foldername As String
        Dim filename As String
        If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
            foldername = FolderBrowserDialog1.SelectedPath()
        Else
            Dim Results As DialogResult = FolderBrowserDialog1.ShowDialog
            If Results = DialogResult.Cancel Then
                Return
            End If
            Exit Sub
        End If
        txtFolderXMLFiles.Text = foldername
        validatexmls(foldername)
    End Sub

Private Function validatexmls(ByVal infile As String) As Boolean
        Dim filename As String
        Dim mydir As New DirectoryInfo(infile)
        Dim m_xmld As XmlDocument
        Dim f As FileInfo() = mydir.GetFiles("*.xml")
        Dim i, j As Integer

        For i = 0 To f.Length - 1
            filename = f(i).FullName
            ' create xml doc
            m_xmld = New XmlDocument
            m_xmld.Load(filename)

            'First we create the xmltextreader
            Dim xmlr As New XmlTextReader(filename)

            'We pass the xmltextreader into the xmlvalidatingreader
            'This will validate the xml doc with the schema file
            'NOTE the xml file it self points to the schema file

            Dim xmlvread As New XmlValidatingReader(xmlr)

            ' Set the validation event handler
            AddHandler xmlvread.ValidationEventHandler, AddressOf ValidationCallBack
            m_success = True 'make sure to reset the success var

            ' Read XML data
            While (xmlvread.Read)
            End While
            'Close the reader.
            xmlvread.Close()
        Next
        'The validationeventhandler is the only thing that would
        'set m_Success to false
        Return m_success
    End Function

Private Sub ValidationCallBack(ByVal sender As Object, ByVal args As ValidationEventArgs)
        'Display the validation error. This is only called on error
        m_success = False
        Dim mywriter As System.IO.TextWriter
        mywriter = System.IO.File.CreateText("ValidationError.log")
        mywriter.WriteLine("Validation error: " + args.Message)
        mywriter.Close()
        WriterBox.Text = ("Validation error: " + args.Message)
    End Sub

Thanks,
Shailesh


 
Old September 12th, 2005, 07:00 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem has been solved!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with validating vanila XML with XSD joshuaa XML 6 August 21st, 2008 01:42 PM
Creating an XML file from XSD squatss C# 4 January 16th, 2007 08:41 AM
Merging XSD files in one XSD file by using what? haoxuqian XML 1 November 4th, 2005 01:42 PM
Validating XML against XSD ShaileshShinde General .NET 0 September 20th, 2005 01:22 AM
Transform .xsd files to a .xml file lxu XSLT 0 July 19th, 2004 09:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.