Re: XSD validation, ambiguous root XML instance element

Michael Kay writes:

> Basically, the problem is that XSD doesn't define constraints on a
> document, it only defines constraints on an element. I've never
> understood entirely why that mind-set exists, but it seems to be
> strongly held by some.
>
> xs:ID/IDREF validation is of course an exception, and I think that
> only got in because they wanted XSD to be a functional replacement for
> DTDs.

At this remove in time, I certainly don't remember why we didn't add a
document-level constraint to XSD.  But I would note that insofar as
there was a mind-set, it was certainly heavily influenced by the idea
that, as you said, XSD was meant to do more-or-less what DTDs did, using
XML as its notation.  And DTDs don't let you specify the root element
either.

Why _that_ was the case I have no idea.

Nor do I remember why the XML DOCTYPE _does_ specify the root element,
which is redundant/self-evident 99% of the time.

But mentioning DOCTYPE leads on to suggest that one might say the
'correct' way to address your requirement is to put the constraint _in
the document_:

<!DOCTYPE X>
<?xml version="1.0"?>
<X>
...
</X>

Or, and IIRC at least some validators provide for this, specify the
required root element name or type when invoking the validation.

ht
-- 
       Henry S. Thompson, School of Informatics, University of Edinburgh
      10 Crichton Street, Edinburgh EH8 9AB, SCOTLAND -- (44) 131 650-4440
                Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
                       URL: http://www.ltg.ed.ac.uk/~ht/
 [mail from me _always_ has a .sig like this -- mail without it is forged spam]

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

Received on Tuesday, 3 November 2020 10:10:08 UTC