簡體   English   中英

楊 model 僅當條件為真時強制節點

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

我有一個 XML 文件:

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

和一個楊model:

container a {
   leaf b {
      type boolean;
   }

   leaf c {
      type string;
   }
}

僅當節點“b”等於“真”時,節點“c”才是強制性的。 如果我向節點“c”添加強制:真約束,它將成為所有“b”值的強制約束。

如何更改 Yang model 以便在“b”為“真”時節點“c”是強制性的,而當“b”為假時是可選的?

您可以must語句XPath條件一起使用:

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

   leaf c {
      type string;
   }
}

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