Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

Yang model mandatory node only when condition is true

I have an XML file:

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

and a Yang model:

container a {
   leaf b {
      type boolean;
   }

   leaf c {
      type string;
   }
}

Node 'c' is mandatory only when node 'b' equals 'true'. If I add a mandatory: true constraint to node 'c' it will become mandatory for all values of 'b'.

How to change the Yang model so that node 'c' is mandatory when 'b' is 'true' and optional when 'b' is false?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the must statement with an XPath condition:

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

   leaf c {
      type string;
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...