views:

67

answers:

3

This isn't a question about why XML is used for configuration files. My question is why, when XML is used for configuration files, there's no accompanying schema.

log4net is a good case-in-point. You can configure it programmatically, but it's preferred that you use XML. Fine, but then why does it have to be so hard?

In Visual Studio when I'm typing XML with a schema, I get nice Intellisense as I go. Without one, I'm having to guess at every element and attribute, since there never seems to be a comprehensive listing. The XML becomes Disgusting XML, the kind that's error-prone and tedious to type.

Those of you who've worked on such projects: Why do you release them with documentation and XML comments and samples, but no XML schema to make configuration easier? Is it laziness? Is there a genuine motive behind it? Did no one think of it?

+2  A: 

I think the main reason is, that in the most cases you already put your expectation about what you expect in a document in the code that evaluates the xml. Therefore a schema could be seen as extra work. And even in open-source work is not for free... ;D

hackbert
+3  A: 

I believe that while most developers understand XML quite well, and with that knowledge they can build programs that read XML configuration files, XML schemas aren't nearly as well understood.

This is probably made worse by the fact that most tools for writing XML schemas either cost a good bit of money, or are freely available, but then not very good or nice to work with. It then becomes just a little bit more difficult to seriously experiment with XML schemas.

(I know, of course a text editor should be enough for writing both XML and XSD. But it often makes a crucial difference whether specialized tools are available or not, IMHO.)

stakx
But in Visual Studio it's easy to auto-generate a schema, and it's reasonably easy, from that, to improve it as need be. And if you're writing the open source library, you have all the range of config options at your disposal, so you know what the schema should allow.
Kyralessa
@Kyralessa: But can you also *express* your configuration options in valid XSD? (I couldn't.) While Visual Studio's ability to (partially) infer XSD from an XML document, it won't necessarily get it right, so you'll still have to know XSD to fix or complete the output.
stakx
Granted, I can't necessarily specify every valid value (or a range of valid values) for a given element or attribute. But I *can* at least say which elements and attributes belong where. Why would people think that the schema shouldn't exist unless it's absolutely perfect? A .xsd that just shows where the elements and attributes go is a major time-saver (because of autocomplete) when you have to type XML configuration by hand.
Kyralessa
+1  A: 

Nah, I'm not going to bother with an XSchema because the standard is clunky, inflexible, and doesn't provide anything beyond basic typed-syntactic validation.

So it allows me to define a grammar for the file, and basic datatypes for the values, but I'm still going to have to write my own verification routines for any non-trivial parameters. Even then, the inability to define my own lexical forms, or define my own restrictions or extensions of basic xsd datatypes beyond basic range constraints, renders the spec incapable of expressing the syntactic forms I would need to make it truly useful even for syntactic validation.

Just consider how you might declare that the text() of an element should be a valid ISBN? Or a valid filename/directory-path? Or a prime number? Or a leap-year? etc? etc? etc?

Personally I might provide you with a DTD if you're lucky (ie. an untyped EBNF in a weird format). I might even run an automatic DTD to RelaxNG converter over it and clean up the result for you. But don't expect me to write a schema. If I'm wanting to provide true validation support, you won't be getting an XSchema anyway; rather, I'll be handing you GRDDL+OWL, where between XSLT and the power of a declarative FOL constraint language, I can actually declare validations that are worth doing.

Recurse
You're going from one extreme to the other. I'm not looking for a schema that'll validate every single value I put it in. I'm looking for something that'll work with Visual Studio's intellisense (in a .xml file) to give me an idea of what elements and attributes are valid. Granted, I still may have to refer to the documentation, but at least a schema would make entering the data less painful by not requiring me to type everything out. For configuration-heavy stuff like NHibernate, I don't see why this isn't done.
Kyralessa