Name

rng:optional — Matches zero or one occurrences of whatever its children match

XML syntax example

<element name="date"
 datatypeLibrary="http://www.w3.org/2001/XMLSchema-
 datatypes">
 <optional>
  <element name="mydate">
   <data type="dateTime" />
  </element>
 </optional>
</element>

Compact syntax example

element date { element mydate { xsd:dateTime }? }

Parents

attribute, choice (( ) and |), define (name of pattern followed by =), element, except (-), group (( ) and ,), interleave (&), list, mixed, oneOrMore (+), optional (?), start (start followed by =), zeroOrMore (*)

Description

The optional pattern matches a pattern of zero or one of whatever its children match. In the compact syntax, optional is represented by a question mark, as in DTDs. If multiple child patterns are present, they are treated as if they were wrapped by a group pattern.

See also

§1, oneOrMore, zeroOrMore

Get XML Pocket Reference, 3rd 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.