简体   繁体   English

杨 model 仅当条件为真时强制节点

[英]Yang model mandatory node only when condition is true

I have an XML file:我有一个 XML 文件:

<a>
    <b>true</b>
    <c>foo</c>
</a>

and a Yang model:和一个杨model:

container a {
   leaf b {
      type boolean;
   }

   leaf c {
      type string;
   }
}

Node 'c' is mandatory only when node 'b' equals 'true'.仅当节点“b”等于“真”时,节点“c”才是强制性的。 If I add a mandatory: true constraint to node 'c' it will become mandatory for all values of 'b'.如果我向节点“c”添加强制:真约束,它将成为所有“b”值的强制约束。

How to change the Yang model so that node 'c' is mandatory when 'b' is 'true' and optional when 'b' is false?如何更改 Yang model 以便在“b”为“真”时节点“c”是强制性的,而当“b”为假时是可选的?

You can use the must statement with anXPath condition:您可以must语句XPath条件一起使用:

container a {
   must 'not(b) or boolean(c)'
  
   leaf b {
      type boolean;
   }

   leaf c {
      type string;
   }
}

Yang1.1 support optional mandatory Yang1.1 支持可选强制

container a {  
   leaf b {
      type boolean;
   }

   leaf c {
      when "../b";
      mandatory true;
      type string;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM