Choice Node

YANG allows the data model to segregate incompatible nodes into distinct choices using the "choice" and "case" statements. The "choice" statement contains a set of "case" statements that define sets of schema nodes that cannot appear together. Each "case" statement may contain multiple nodes, but each node may only appear in one "case" under a "choice".

When a case from one choice node takes effect, all the other cases in the choice node are implicitly deleted. The device handles the enforcement of the constraint, preventing incompatibilities from existing in the configuration.

The choice and case nodes appear only in the YANG model file, not in NETCONF messages.

YANG example:

container food {
 choice snack {
  case sports-arena {
   leaf pretzel {
    type empty;
   }
   leaf beer {
    type empty;
   }
  }
  case late-night {
   leaf chocolate {
    type enumeration {
     enum dark;
     enum milk;
     enum first-available;
    }
   }
  }
 }
}

NETCONF XML example (excluding the choice and case nodes):

<food>
 <pretzel/>
 <beer/>
</food>
Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic