简体   繁体   English

如何 model 没有公共子元素的 YANG 列表?

[英]How to model a list in YANG with no common child elements?

I have an XML that looks like this.我有一个看起来像这样的 XML。

<c>
    <node>
       <id1>value</id1>
       <id2>value</id2>
    </node>
    <node>
       <id3>value</id3>
       <id4>value</id4>
    </node>
</c>

How can this list be modeled in YANG?这个列表如何在 YANG 中建模? The problem here is that every list requires a key.这里的问题是每个列表都需要一个键。 What I tried to do:我试图做的事情:

container c {
  list node {
    key ""; /* What is the key? */
    leaf id1 {
      type string;
    }
    leaf id2{
      type string;
    }
    leaf id3 {
      type string;
    }
    leaf id4 {
      type string;
    }
  }
}

There is no good way to model this in YANG. model 这个在 YANG 没有好办法。 Like you say, every (config true) list requires a key.就像您说的那样,每个(配置为真)列表都需要一个密钥。 Designating a leaf as a key makes that leaf mandatory, so you can't really have an instance document like in your example - if you make all four leafs to be keys (which you can as there may be multiple list keys) each node has to have all of them to be valid, and making just a couple of them to be keys, doesn't work for your example either.将叶子指定为键会使该叶子成为强制性的,因此您不能真正拥有像示例中那样的实例文档 - 如果您将所有四个叶子都设为键(您可以这样做,因为可能有多个列表键)每个节点都有让所有这些都有效,并且只让其中几个成为键,也不适用于您的示例。

Note that a config false list does not need to have any keys.请注意,配置错误列表不需要任何键。 If you are not modeling configuration (or NETCONF/RESTCONF related data), that may be your way out.如果您不是对配置(或 NETCONF/RESTCONF 相关数据)进行建模,那可能是您的出路。

list node {
  config false;
  // ...
}

Otherwise, you have no choice - you need to introduce another leaf to serve as an id for an entry.否则,您别无选择 - 您需要引入另一个叶子作为条目的 id。

Either way, you would probably utilize the unique statement (I'm assuming based on names of your leafs), to make entries in the list unique.无论哪种方式,您都可能会利用unique语句(我假设基于您的叶子名称)来使列表中的条目唯一。 It works in a similar way as key , but elements need not appear in an instance document if you use it - it only requires that the combination of nodes that do appear in the instance is unique across all entries of a list.它的工作方式与key类似,但如果使用它,元素不需要出现在实例文档中 - 它只要求出现在实例中的节点组合在列表的所有条目中是唯一的。

list node {
  config false;
  unique "id1 id2 id3 id4";
  // ...
}

Note: there is a similar answered question with some more details.注意:有一个类似的已回答问题,其中包含更多详细信息。

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

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