?
Solved

Help with  validating specific xml file in a multiple folders using VB.NET

Posted on 2014-11-09
3
Medium Priority
?
30 Views
Last Modified: 2016-06-23
Hi,

How do you modify the code below to validate xml files in multiple folders? For example I need to validate NSNBEL.XML in \Data\MasterNSN folder,  NSCBEL.xml in \Data\MasterNSN folder, but the .xsd files in the MasterFiles folder does not include the country, for example it contains NSN.xsd, NSC.xsd. Is there a way to but the folders in a string variable and use a loop instead of writing the same code for each folder and country. When I only one to validate for each country at a time not all countries in the folder.

 On Error GoTo tt
        Dim zz As String = ""
        For Each File As String In IO.Directory.GetFiles(Application.StartupPath + "\Data\MasterFuze\")
            Dim settings As New XmlReaderSettings
            settings.ValidationType = ValidationType.Schema

            settings.Schemas.Add(XmlSchema.Read(New XmlTextReader(Application.StartupPath + "\Data\MasterFiles\" & IO.Path.GetFileNameWithoutExtension(File) & ".xsd"), AddressOf ValidationHandler))

            Dim reader As XmlReader = XmlReader.Create(File, settings)
            zz = File

            Dim doc As New XmlDocument()
            doc.Load(reader)
        Next

        MsgBox("Master Files Validated")
        Exit Sub

Open in new window


Thanks,

Victor
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
ElrondCT earned 2000 total points
ID: 40437709
Should the folder name in lines 3 and 7 be the same?

You could make this code into a function to which you pass the folder you want to validate:
    Private Function ValidateXML(ByVal CheckFolder As String) As Boolean
        On Error GoTo tt
        Dim zz As String = ""
        Dim File As String
        For Each File In IO.Directory.GetFiles(Application.StartupPath & CheckFolder)
            Dim settings As New XmlReaderSettings
            settings.ValidationType = ValidationType.Schema

            settings.Schemas.Add(XmlSchema.Read(New XmlTextReader(Application.StartupPath & CheckFolder & IO.Path.GetFileNameWithoutExtension(File) & ".xsd"), AddressOf ValidationHandler))

            Dim reader As XmlReader = XmlReader.Create(File, settings)
            zz = File

            Dim doc As New XmlDocument()
            doc.Load(reader)
        Next

        MsgBox("Master Files Validated")
        Return True

tt:
        MsgBox("Validation Error in " & File)
        Return False

    End Function

Open in new window


Then call it with each folder you want to check:
        blnValid = ValidateXML("\Data\MasterFiles\")
        blnValid = ValidateXML("\Data\MasterNSN\")

Open in new window

0
 

Author Comment

by:vcharles
ID: 40446951
Thank you for your solution, will test it and getback to you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question