[opencms-dev] Structured content, XSD, default value of optional element

Paul-Inge Flakstad flakstad at npolar.no
Thu Apr 30 16:12:38 CEST 2009


Hi list members,

I have a structured content type that I'm using a lot, and I'm wondering if it is possible to assign an (empty string) default value to an element defined as optional in the XML schema (XSD), or - in other words - make an optional element "present" in the editor as default, rather than "not present".

Example: my XSD that has this element definition:
<xsd:element name="Title" type="OpenCmsString"  minOccurs="0" maxOccurs="1" />

The editor correctly notes that this element is optional, and consequently makes it "non-present", you'll have to click on the [+] button to add it. I want it the other way around - "present" by default, so I will have to press the [x] button to remove it.

I do not want minOccurs="1" and maxOccurs="1", since sometimes the "Title" element will not be given a value. But 90% of the time, the "Title" element will be given a value, and it's very frustrating to have to click on the [+] icon for each one, and waiting for the page to reload each time (there are usually many occurences of this element, and similar elements, in a single page).

I tried changing the definition to

    <xsd:element name="Title" type="OpenCmsString"  minOccurs="0" maxOccurs="1" default="" />

        and also

    <xsd:element name="Title" type="OpenCmsString"  minOccurs="0" maxOccurs="1" default="xx" />

but that didn't work, as the element will not be "present" until you click the [+] button.

Is it at all possible to accomplish what I want, or is the only solution to make it non-optional (skip the minOccurs="0" part)?

Thanks,
Paul

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20090430/350dc288/attachment.htm>


More information about the opencms-dev mailing list