views:

97

answers:

1

Hi

I am planning to try to use XML Serialization in C# but I am wondering if I get a .xml file how do I check if the xml file confirms to the right type?

Like usually you would make a schema that you can validate against to make sure if it confirms to the right format.

Can you hook a schema up to to XML Serialization or does it do this checking automatically?

Thanks

+2  A: 
Raj Kaimal
In practice, I always validate the XML with and XSD prior to deserialization. This catches things like required fields, range errors and malformed XML, prior to attempting the deserialization.
Robert Harvey
Do you mean manually or through code you validate it?
chobo2
Are we taking about serializing a type (say Employee class) into xml and serializing it or are we referring to the process of validating an xml file using an xsd? In the former case, there is no xsd involved.
Raj Kaimal
I am talking about xsd. Like I created my schema with rules that say this and that are required. I then made my serialization class manually and I just removed a tag from my xml file and it still does deserialization just fine.
chobo2
Ya I did that. I don't like how it generates the stuff though so I did it by hand but even looking at the element in question(in the generated file) they do put anything on it to make it so that it can only show up once and has to show up once. In my schema I set on that element minOccurs="1" maxOccurs="1".
chobo2