Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 October 21st, 2005, 11:28 PM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validate xml files present in subfolders

Hi All,

Presently I am browsing to a folder which contains xml files. futher i do validation against xsd.
But now I have to do some thing like this: When i select say folder1 in that subfolder1, subfolder2 and so on. these subfolders contains xml file which i have to validate against xsd. How do my code select files from subfolders and futher validation?

My code:

visual basic code:
Private Sub btnInputXMLFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputXMLFile.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
            mstrFolderXMLFiles = FolderBrowserDialog1.SelectedPath()
            txtInputXMLFile.Text = foldername
        End If
                validatexmls(mstrFolderXMLFiles)
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
        Try
            If RadioButton2.Checked Then

                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)
                    Dim sc As XmlSchemaCollection = New XmlSchemaCollection
                    AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack
                    sc.Add(Nothing, mstrInputXSDFile.Trim)
                    '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)
                    xmlvread.ValidationType = ValidationType.Schema
                    xmlvread.Schemas.Add(sc)
                    ' 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
                If m_success Then
                    WriterBox.Text = "No Validation Errors"
                Else
                    MsgBox("Validation Errors")
                End If
            End If

        Catch a As UnauthorizedAccessException
            'dont have access permission
            m_success = a.Message
        Catch a As Exception
            'and other things that could go wrong
            m_success = a.Message
        End Try
        'The validationeventhandler is the only thing that would
        'set m_Success to false
        Return m_success
    End Function






Similar Threads
Thread Thread Starter Forum Replies Last Post
? - Is there a way to validate 1 XML record at a t bobk544 XML 0 January 7th, 2005 02:37 PM
How to Validate a Date for present and Future Cute Designer J2EE 1 November 9th, 2004 10:45 PM
Validate an XML through XSD telliegeorge BOOK: Beginning Visual C++ 6 0 February 2nd, 2004 04:58 PM
uploading large files a 4Mb limit seems present! Grahame2003 C# 2 December 4th, 2003 05:09 AM





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