Not validating XML and just deserializing it and catching exceptions: is this a good approach???

  • Thread starter Thread starter Bob Rock
  • Start date Start date
B

Bob Rock

Hello,

always having to validate an XML stream against a XSD may add up an
important overhead. My XMLs are usually the result of serializing a
class instance and often in my applications what I end up doing is
just deserializing it back into a new instance of the same class.
Considering what I just said what I often end up doing is not
validating my XML to be deserialized and just try deserializing it
into an instance of the class and catch proper exceptions handling
them (and eventually doing the validation there to identify the exact
issue at hand).

Now, it this approach good? I mean, are there situations where a XML
that is not conform to an XSD still may get correctly deserialized
into an instance of my class? In other words, are there situations
where an incorrect XML may go undetected by using my approach???

Bob Rock
 
Hi Rob
it is always better to double check if the XML still adhere to your
appropriate format .Still your approach , the one you are following now is
ok . since the XML that don't follow the XSD will fail into the
deserialization process throwing an exception. So, you can use this as
your primary validation , no need to revalidate
hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top