Suppose I have an XML like this:
<foo ...>
<bar a="s1" b="s2" />
<bar a="s3" />
</foo>
What I'd like is to define in the XSD is that the default value of attribute b
should be the value of attribute a
. Is that possible?
Thanks in advance!
Short answer: no.
Medium answer, according to "XML Schema Part 1: Structures Second Edition", section "3.2.1 The Attribute Declaration Schema Component": "default specifies that the attribute is to appear unconditionally in the ·post-schema-validation infoset·, with the supplied value used whenever the attribute is not actually present"
Long and practical answer: the key is "post-schema-validation infoset". So ask yourself what you need the schema document for?
use="required"
for attribute b
XmlSerializer
) then you must explicitely add some post-processing which satisifies this "post-schema-validation-infoset" term - you should detect if the value of b
wasn't set and set it yourself - that's your business requirementb
as having the same value as a
) add documentation. XML Schema doesn't have such concept. Using extrapolation - that would be the same requirement as "the value of b
will be the current USD/EUR ratio" - it's just computed value