From: Brian Allison (brian_at_[hidden])
Date: 2006-04-24 08:48:59


Thorsten Ottosen wrote:

>Daniel Walker wrote:
>
>
>>On 4/23/06, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
>>
>>
>
>
>
>>>>Schemas give you data types and type checking, which obviously is
>>>>nice to have when you're dealing with data. I think XML schema
>>>>validation is one of the most import features of XML for the same
>>>>reason that I like C++ templates and type-safe compile time
>>>>polymorphism: making sure your data types are correct before hand
>>>>gives you one less thing to worry about.
>>>>
>>>>
>>>Why is that better than a run-time exception when loading the file?
>>>
>>>
>>Why is what better? Maybe I wasn't clear. When an XML file includes a
>>schema and fails validation when loaded, you do get a run-time
>>exception. I was trying to say that's a good thing. An XML validating
>>parser is similar to a compiler for a strongly typed language: it
>>catches type errors (in addition to syntax errors) immediately before
>>you actually try to use the file.
>>
>>
>
>Ok, why is that exception better than the one I generate if I don't meet
>the tag I expect, of if the contents of a tag is not of the type I expect?
>
>-Thorsten
>_______________________________________________
>Unsubscribe & other changes: http://listarchives.boost.org/mailman/listinfo.cgi/boost
>
>
>
>
It's not that the exception is atomically better, but the question seems
similar to the old-time 2-phase construction programmer asking why it's
better to avoid 2-phase construction. The parsing/validation of XML
allows me to trust that my data structure has been constructed fully and
as a valid foo - or that an exception was thrown for some appropriate
reason. For XML, malformed XML itself is akin to a constructor call
where it can only be determined to be malformed at runtime.

In fact, in each of the places where I've used XML to transmit data , it
has been a representation of an invariant. This is no different than a
class which properly represents an invariant, and I prefer not to be
able to receive broken objects from factories.

Pardon me if I'm missing the point of your question...

Brian Allison