Xml validation

Feb 11, 2011 at 6:07 PM


does this tool support xml validation against a xsd schema?

if so, how to do that?

if not, any idea of how to do that in a silverligth application?


Feb 21, 2011 at 8:42 PM

No, sorry but xsd2code can't validate xml data against a schema.
Perhaps in next release.


Mar 2, 2011 at 9:26 AM
Edited Mar 2, 2011 at 9:33 AM

If your using Deserialize, you can do it by adding (Folder/File.xsd as example, replace it accordingly to your solution)


stringReader = new System.IO.StringReader(xml);
return ((T)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader, settings))));


stringReader = new System.IO.StringReader(xml);
System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
using (var reader = System.Xml.XmlReader.Create(System.Windows.Application.GetResourceStream(new Uri(@"pack://application:,,,/Folder/File.xsd")).Stream))
    settings.Schemas.Add(null, reader);
settings.ValidationType = System.Xml.ValidationType.Schema;
return ((T)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader, settings))));

Make sure you set File.xsd, Build Action to Resource.
But do Note this throw a exception if the  xml is not valid

Feb 10, 2012 at 6:25 PM

This is an interesting thread.

Would you consider extensions to xsd2code to support something like  VAB (Enterprise Library Validation Application Block)?

It could either generate attributes for validation, or perhaps even easier generate XML VAB configuration - perhaps that could be done with something as simple as XSLT?