Validating XML document against an XML Schema with VB.Net

It seems like validating an XML document against a schema would be a pretty simple thing to do in the .Net framework, seeing as how they have such deep support for dealing with XML.

But as of yet, I haven’t found a simple way to do it.

Here is the code I have been using to validate XML against an XML Schema.

Imports System.IO
Imports System.Xml
Imports System.Xml.Schema


Private schemaValidation As New ValidationEventHandler(AddressOf ValidationHandler)

Private Function ValidateXml(ByVal xmlFileName As String, ByVal xmlSchemaName As String) As Boolean
Using myFile As New FileStream(xmlFileName, FileMode.Open, FileAccess.Read, FileShare.None)
Dim xDoc As New Xml.XmlDocument()
xDoc.Load(myFile)
xDoc.Schemas.Add(GetSchema(xmlSchemaName))
Try
xDoc.Validate(schemaValidation)
Return True
Catch ex As XmlSchemaValidationException
Console.Write(ex.ToString)
Return False
Catch ex As XmlSchemaException
Console.Write(ex.ToString)
Return False
Catch ex As Exception
Console.Write(ex.ToString)
Return False
End Try
End Using
End Function

Private Function GetSchema(ByVal filePath As String) As XmlSchema
Dim schema As XmlSchema
Using s As New System.IO.FileStream(filePath, FileMode.Open)
Using reader As New StreamReader(s)
schema = XmlSchema.Read(reader, Nothing)
End Using
End Using
Return schema
End Function

Private Sub ValidationHandler(ByVal sender As Object, ByVal e As System.Xml.Schema.ValidationEventArgs)
Throw e.Exception
End Sub
 

Here Is A Article Talking About The Ability To Put Some Of Your Config Info In Another Config File When Using Aspnet

Here is a article talking about the ability to put some of your .config info in another config file when using asp.net

http://www.beansoftware.com/ASP.NET-Tutorials/Multiple-Config.aspx

What I found most interesting is that it says that changing the otherFile.config will not reset your app.

I am guessing that it also means that it won’t find your new values until the app is reloaded, but if it DID find the new values w/o a reload that would be great.

<?xml version=1.0?>
<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <compilation debug=false strict=false explicit=true />
    </system.web>
    <appSettings file=externalSettings.config/>
</configuration>

I also wonder if you could have more than 1 appSettings external file.

Some Good Links For Updating Cisco PIX Devices

Problem getting PDM running:
http://www.experts-exchange.com/Security/Firewalls/Q_21611023.html

Installing PDF on a Pix Firewall:
http://www.cisco.com/univercd/cc/td/doc/product/iaabu/pix/pix_61/pdm_ig/pdm_inst.htm

Upgrade/Update/Flash a Cisco Pix:
http://www.windowsitpro.com/Article/ArticleID/20281/20281.html?Ad=1

Change Password on Pix:
http://www.linuxhomenetworking.com/cisco-hn/dsl-pix.htm

Sorting a generic List(Of T) using IComparable(Of T)

List(Of T) supports sorting through it’s Sort method.  When you call Sort it will use the default comparer for the items it contans.  So if you have a custom class in there, you need to implement IComparable or IComparable(Of T). 

Here is some code that shows how to do this.  This code sorts lowest to highest.

    Public Function CompareTo(ByVal other As CustomClass) As Integer Implements System.IComparable(Of CustomClass).CompareTo
Dim myscore As Integer = Me.SomeValue
Dim otherscore As Integer = other.SomeValue
If myscore > otherscore Then
Return 1
ElseIf myscore = otherscore Then
Return 0
Else
Return -1
End If
End Function

My Sansa e200 Review

I figure I should put up a review of my Sansa e200 incase anyone else is thinking of getting one.

I had a couple trips I had to take last month and my old Archos mp3 player decided to die on me.  Luckly for me I was able to find a Sankdisk Sansa e200 or e220 or e2XX whatever.  My model is the 6GB version, which is the largest they offer at the moment.

The unit cost $280 at Circuit City and while I could have got it online for $250 or so, I was going to be on a plane the next day so I didn’t mind paying a little extra to have it with me on the trip.  Have I mentioned that I hate Circuit City?  Why is it that every time I got there I end up getting frustrated or pissed off?  I guess the one time I went there to see a TiVo demoed was ok… except now that I think about it they didn’t know how to work the Tivo.  I ended up buying one and loving it though (this was back in ’99).

Anyway, I have to say I am very pleased with the Sansa.  It was exactly what I hoped it would be in almost every way.

Battery life is awesome.  I think I read somewhere that it does 15 hours, which sounds about right.  I haven’t had it run out on me yet.  Oh, this does bring me to one of the few things I don’t like about it.  You can’t listen to it while you have it connected to your computer, which means you can’t listen to it while you are charging it thorough the USB.  Maybe you could “disconnect” through windows and have it still get power, but I don’t know.

Playback quality and volume are good.

Navigation is IPod-like, which is ok, but rather than use a “touch wheel” they have an actual wheel you can turn that makes navigating easier in my opinion.  The only thing I don’t like about navigation is that if you want to change to a song on another album by the same artist, you have to click Menu (down), Back To List (Middle), and then “Back” (Right).  I guess there is not obvious way to improve that, so overall I can’t really complain.

FM Radio / Video: Well I will never be using the video, and I am sorry to say that as soon as I started using the FM radio I realized how much I would have rather had AM.  Oh well.

Audio Recorder: Haven’t used it.

Graphics: I was a little suprised that there were now “Themes” to choose from, only the 1 default theme.  It’s not bad, just something I would have figured they would do.  They show the album cover if you downloaded it, which is cool.

PC Integration: Awesome.  My winXP computer saw it right away as some kinda media device, no driver installs or anything.  You go to My Computer, click on the Sansa icon (it’s almost like an external hard drive), and you just drag over your folders.  Once loaded, the Sansa will look at your MP3 tag info and index them all like the IPod does.

My wife bought me a little rubber case for it that I leave on all the time, and I have no worries about it breaking.  The thing feels really solid. 

Size: It looks bigger in these pictures than it is.  It’s smaller than a large pack of gum.  Very nice.

Overall I am very happy with it!!  I would really recommend it to anyone who wants a great MP3 player, but doesn’t want to get stuck with an IPod.