What I like to do: I want to specify an option tag in the schema, for example:
<xsd:element name="my_element" type="my_type" minOccurs="0" maxOccurs="1"/>
If the element does not occur at all, there should be a default value for this parameter. Of course I could define this default value in my code, which calls the XML parser. But I think the correct place to specify the default value would be in the *.xsd schema file (since the default value is part of the interface defined by the schema).
Unfortunately this does not seem to be easy. The "default" attribute has a different effect: "if it does not appear it is not provided; if it does appear and it is empty, its value is the default value" (from http://www.w3.org/TR/xmlschema-0/#ref36).
Other links I've found discussing this issue:
Is there a solution to this problem? Or should I give up?
simple elements may have a default value OR a fixed value specified.
A default value is automatically assigned to the element when no other value is specified.
In the following example the default value is "red":
<xs:element name="color" type="xs:string" default="red"/>
A fixed value is also automatically assigned to the element, and you cannot specify another value.
In the following example the fixed value is "red":
<xs:element name="color" type="xs:string" fixed="red"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With