Element Default Values

This should cover W3C XML Schema, Relax NG and DTD related problems.
integragreg
Posts: 4
Joined: Mon Jun 27, 2005 5:22 pm
Location: USA
Contact:

Element Default Values

Post by integragreg » Tue Nov 22, 2005 7:55 pm

Hi,

I want to be able to automatically assign a default value for an element whenever I create a new xml document that is based on a particular schema definition. Can anyone tell me how to specify this in my xsd?

Thanks!

Greg

integragreg
Posts: 4
Joined: Mon Jun 27, 2005 5:22 pm
Location: USA
Contact:

Clarification

Post by integragreg » Tue Nov 22, 2005 8:24 pm

I should probably clarify my last post.

What I want to do is have the default values automatically appear in the xml document when Oxygen generates it from the schema. I don't intend to use the default or fixed attributes in the element declaration, because I want to be able to change the value if necessary. I merely want there to be suggested default values that appear when the document is generated.

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Clarification

Post by sorin_ristache » Wed Nov 23, 2005 12:14 pm

Hello,
integragreg wrote:I don't intend to use the default or fixed attributes in the element declaration
What is the default value that you expect if you don't use the default or fixed attribute in the declaration ?

Regards,
Sorin

integragreg
Posts: 4
Joined: Mon Jun 27, 2005 5:22 pm
Location: USA
Contact:

Post by integragreg » Wed Nov 23, 2005 1:22 pm

Thanks for the reply, Sorin.

The XML file that is derived from the schema is a configuration file for a software application. What I want to be able to do is generate the file from the schema and automatically insert specific element values when it's generated.

For example, let's say that my schema defines the following set of elements:

<xs:element name="serialportsettings" form="qualified">
<xs:complexType>
<xs:sequence>
<xs:element name="comport" form="qualified" type="xs:int"/>
<xs:element name="baudrate" form="qualified" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>

When Oxygen generates the XML file from this schema, I'd like for the output to automatically contain the default values of 1 and 9600 for the comport and baudrate elements, like so:

<serialportsettings>
<comport>1</comport>
<baudrate>9600</baudrate>
</serialportsettings>

This way, the person who generates the xml file will be given default values that they can change if they choose to do so.

I'm beginning to think that this might be better accomplished using xslt, rather than trying to force this through the schema. Maybe the schema definition language was not intended to be used for what I am trying to accomplish.

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Wed Nov 23, 2005 1:37 pm

Hello,

Generation of a sample document containing default values in the elements from a specified schema will be added in a future version of <oXygen/>. The current version can only generate empty elements when a new document is created based on a schema. When the feature will be added to <oXygen/> the value specified in the default attribute of xsd:element could be inserted as default element content.

Regards,
Sorin

integragreg
Posts: 4
Joined: Mon Jun 27, 2005 5:22 pm
Location: USA
Contact:

Post by integragreg » Wed Nov 23, 2005 4:42 pm

Thanks. is there a projected schedule for when this feature will be released?
Cheers,

Greg

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Thu Nov 24, 2005 12:29 pm

Hello,

It is scheduled to be included in the next release of <oXygen/> so probably the next version will include it.

Regards,
Sorin

Post Reply