Francesco Geri

Il blog di Francesco Geri
posts - 56, comments - 57, trackbacks - 2

My Links

News



Anch'io metto nel mio blog cose che scrivo così, tanto per fare, tanto per condividere miei appunti, senza prendermi la briga di garantirne l'infallibilità, né l'assoluta correttezza, senza pretese e con grande umilté.

Quanti mi hanno visto dal 25/10/2007:
...dettagli

Che libro leggo in questo periodo?*

L'Affittacamere - Valerio Varesi
* L'immagine è presa da IBS (http://www.ibs.it), spero non me ne vogliano...

Archives

Post Categories

Altre

Blogs

Validazione di un file XML dallo schema XSD

Liberamente tratto da MSDN riporto il codice per la validazione di un file XML da uno schema XSD.

 

   1:  Imports System
   2:  Imports System.Xml
   3:  Imports System.Xml.Schema
   4:  Imports System.IO
   5:   
   6:  Public Class Sample
   7:   
   8:     Public Shared Sub Main()
   9:   
  10:        ' Create the XmlSchemaSet class.
  11:        Dim sc As XmlSchemaSet = New XmlSchemaSet()
  12:   
  13:        ' Add the schema to the collection.
  14:        sc.Add("", "Schema.xsd")
  15:   
  16:        ' Set the validation settings.
  17:        Dim settings As XmlReaderSettings = New XmlReaderSettings()
  18:        settings.ValidationType = ValidationType.Schema
  19:        settings.Schemas = sc
  20:        settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings
  21:        AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack
  22:   
  23:        ' Create the XmlReader object.
  24:        Dim reader As XmlReader = XmlReader.Create("MyFile.xml", settings)
  25:   
  26:        ' Parse the file. 
  27:        While reader.Read()
  28:        End While
  29:   
  30:        Console.ReadKey()
  31:     End Sub
  32:   
  33:     ' Display any validation errors.
  34:     Private Shared Sub ValidationCallBack(ByVal sender As Object, ByVal e As ValidationEventArgs)
  35:        Console.WriteLine("Validation Error: {0}", e.Message)
  36:     End Sub
  37:  End Class

Print | posted on giovedì 25 ottobre 2007 19.50 | Filed Under [ Tips .Net XML ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 2 and 1 and type the answer here:

Powered by: