Re: [xml] Making sequence entries option in .xsd files.

On 08/06/2016 09:40, Steve Underwood wrote:
On 06/06/2016 07:52 PM, Steve Underwood wrote:

In the .xsd file for the DLMS Smart Grid protocol I find the following



By the protocol definition, the first 3 items in that sequence should
be optional. The minOccurs="0" elements cause items 1 and 3 to be
correctly treated as optional. However, the parser in libxml2 2.9.3
treats the second item as a required element. Shouldn't the default
setting act in a similar way to a minOccurs="0" element, in making the
item optional? Is it always necessary to have minOccurs="0" present
when default="something" is present, in order to actually implement
the default?

I have been reading the XSD spec again, and it seems to me the line
in the above XSD definition needs minOccurs="0" adding to it to make the
element optional. I can't find anything in the spec that says
default="xx" has any effect other than to set a default value.

Can anyone confirm or refute this?

You're probably better off asking general XSD questions on the xmlschema-dev w3 org mailing list.

But since I'm here, yes, I believe you need minOccurs="0". If I remember correctly, for reasons best known to itself, the XSD spec says if you have default="true" on an element (attributes are treated differently) then it means if your XML instance includes an empty element (i.e. <response-allowed/> or <response-allowed></response-allowed>), then the value returned by your processor should be "true", not the empty string.

Attributes behave more as you'd expect, but probably still need to be marked 'optional'.

Hope that helps,

Pete Cordell
Codalogic Ltd
Read & write XML in C++,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]