xml schema

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

Tony Johansson said:
First of all does every Xml document have a schema ?
No.

I'm trying to get the right feeling for what a xml schema is ?
As far as I understand it's used for defining a structure how you are
permitted to right your Xml document.

Yes, pretty much.
Is it possible to make a simile to C# in some sensible way.

I have no idea what you mean by this, I'm afraid.
 
Hello!

First of all does every Xml document have a schema ?

I'm trying to get the right feeling for what a xml schema is ?
As far as I understand it's used for defining a structure how you are permitted to right your Xml document.

Is it possible to make a simile to C# in some sensible way.

//Tony
 
Tony Johansson said:
When should a Xml schema be used and when can you skip it ?

It's a bit like static typing vs dynamic typing - XML schema allows you
to validate the XML document to some extent. It also enables editors to
provide the equivalent of Intellisense.

Personally I'm not a massive fan, but it depends on the situation. It's
a good way of conveying a specification in a machine-readable format.
 
Hello!

When should a Xml schema be used and when can you skip it ?

My take on this is that schema validation should be used sparingly in
production. Strict adherence to an XML standard (schema) must be done
during testing between exchanging parties but you should be free to
handle schema validation errors in production.

Ken
 
Hello!
First of all does every Xml document have a schema ?
I'm trying to get the right feeling for what a xml schema is ?
As far as I understand it's used for defining a structure how you
are permitted to right your Xml document.
Is it possible to make a simile to C# in some sensible way.

An XML document without a schema is roughly like a C# object whose
only property is a list of name-value pairs. You can iterate through
the list, but until you do, there's no way to tell what names will be
present or what type each value will have.

An XML document with a schema is like a normal C# object. The type of
the object (just like the schema) shows you the properties and their
types.
 
My take on this is that schema validation should be used sparingly in
production.  Strict adherence to an XML standard (schema) must be done
during testing between exchanging parties but you should be free to
handle schema validation errors in production.

A better rule is to be lax on your input but strict on your output. So
you wouldn't validate XML when reading it, trying to detect and
recover from errors as you go, but you'd validate your outputs, so as
to be sure that it adhers to the spec, and your own program and any
third-party product can read it back correctly.

Also, .NET XML schema validation classes allow one to do incremental
validation, and perform recoverable error handling.
 
Pavel Minaev said:
A better rule is to be lax on your input but strict on your output.

I find it's better to be strict on both input and output. Everyone
being lax on input means that errors on output don't get noticed. Being
lax on input is what got browsers into such a horrible mess as they
tried to work out what invalid HTML was meant to read.

Invalid XML is particularly inexcusable, as it's meant to be machine
generated - if something is generating XML which doesn't conform to the
spec, it is *broken* and you shouldn't work with it IMO.
 
Pavel said:
A better rule is to be lax on your input but strict on your output. So
you wouldn't validate XML when reading it, trying to detect and
recover from errors as you go, but you'd validate your outputs, so as
to be sure that it adhers to the spec, and your own program and any
third-party product can read it back correctly.

Also, .NET XML schema validation classes allow one to do incremental
validation, and perform recoverable error handling.

I would not recommend continue processing XML that is not
valid according to the expected XSD.

Something is wrong and until the reason is invesigated
it could do more harm than good to continue.

Arne
 
Back
Top