Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 3rd, 2005, 08:01 AM
Authorized User
Points: 184, Level: 3
Points: 184, Level: 3 Points: 184, Level: 3 Points: 184, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old September 12th, 2005, 07:00 AM
Authorized User
Points: 184, Level: 3
Points: 184, Level: 3 Points: 184, Level: 3 Points: 184, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem has been solved!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:36 AM.


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