Default and fixed element values

The concept of default and fixed values has traditionally been applicable only to attribute values, and can still be applied to attributes using a schema model (as explained in the previous chapter). However, it is now possible to apply these concepts to element content as well.

Default element content

An element type can be assigned a default content value that is to be inserted automatically when the element is present, but empty. The same Default attribute used in attribute definitions can also be used in element definitions for this purpose:

<element name="companyName" type="string"
                            default="ACME Corp" />

The following examples are then equivalent:

 <companyName/> <companyName></companyName> <companyName>ACME ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.