Requiring Attributes

Martin Hill mch at roe.ac.uk
Wed Nov 30 03:15:30 PST 2005


According to my schema book and the w3schools site you can can require 
an attribute like this:

<xs:attribute name="lang" type="xs:string" use="required"/>

and as I understand it you can restrict it (enumerations, etc) in the 
same as you can simple elements.

Paul said:

 > but let's face it, the prime purpose of xml is for
 > computers to read.

Me? Disagree? Surely not.  But there must be some reason we use such a 
verbose form in unicode...

It's perfectly *possible* to make human-readable forms (eg VOTable, and 
I believe people find it's readability a great benefit), but you do have 
to do some work to get it.  Let's not mention ADQL.

Paul Harrison wrote:
> Patrick Dowler wrote:
> 
>> With respect to the following, is there a way to say that at least one
>> of the attributes must be present? Otherwise, a validating XML parser 
>> cannot fully validate the document and client code has to
>> check for null all over the place. The presence of required elements
>> and attributes is really the most vanilla for of validity checking, and
>> we are going to give that up if everything is nillable :-(
>>
>> I realise that even then, use of xlink makes it impossible for the
>> parser to fully validate... but it would be nice to know (from 
>> successfully
>> parsing) that the document appears to be valid (assuming external 
>> references via xlink are to the correct kind of thing).
>>
> 
> 
> I think that this does illustrate a general design issue in our schema - 
> use elements in preference to attributes where the underlying data 
> structure is a choice
> as then the parser can validate that one of the choice elements is 
> present - this cannot be done with optional attributes. Using more 
> elements to represent things instance documents look even uglier to the 
> human reader, but let's face it, the prime purpose of xml is for 
> computers to read.
> 
> 


-- 
Martin Hill
VOTech Software Engineer @ ROE
www.roe.ac.uk/~mch
+44 7901 55 24 66




More information about the dm mailing list