Have you ever wanted to validate an xml document against a schema, but didn’t have any applications at your disposal to do it?
You can use the schema validate tool on decisionsoft.com:
You upload a schema and an xml doc, and it will attempte to validate the xml against the schema.
Here is a cheat sheet that shows some of the main items when using Regular Expressions (RegEx / RegExp)
regular_expressions_cheat_sheet.png (80.91 KB)
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.
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()
Catch ex As XmlSchemaValidationException
Catch ex As XmlSchemaException
Catch ex As Exception
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)
Private Sub ValidationHandler(ByVal sender As Object, ByVal e As System.Xml.Schema.ValidationEventArgs)
I have tried to councel against sending datasets across web service calls, but we have a lot of instances where this is being done.
One of the problems with this is that datasets get bloated when converted to XML.
So I set out to compare the sizes of:
- Serialized List(Of MyType)
- Serialized DataTable
- Serialized DataSet
- XML Serialized Dataset
I wish I had done some research on this, because I would have quickly been reminded that DataSets always serialize as XML, even if you are using the BinaryFormatter.
There are lots of people out there coming up with their own ideas for how to improve the serialization of datasets:
Anyway, this isn’t really THAT big of a deal, because my real goal wasn’t to improve the dataset serialization, but to simply see what it would be, and compare it to some other ways to serialize data, like in a list of business objects or a datatable.
The results are interesting:
Given a list of 1013 Business Objects (Records) the serialization results are as follows:
|XML Serialzied Dataset
I have read that you can really decrease the size of the dataset by writing your own logic to do the serialization, but as everyone points out that is kind of a pain.