简体   繁体   English

在yang验证期间,如何使yang2dsl忽略输入参数的顺序?

[英]How to make yang2dsl ignore the order of input parameters during yang validation?

I use pyang's yang2dsl for validating input xml instances against yang data model. 我使用pyang的yang2dsl来针对yang数据模型验证输入的xml实例。 But, it throws error when the order of the parameters in the xml instances is not the same as in yang model. 但是,当xml实例中的参数顺序与yang模型中的参数顺序不同时,它将引发错误。 Is there an option to make it ignore the order of parameters? 是否有使其忽略参数顺序的选项? Here's my xml code(example.xml): 这是我的xml代码(example.xml):

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="100">
<action>
<param1>aaa</param1>
<param2>bbb</param2>
</action>
</rpc>

Here's my YANG model, example.yang(I've pasted only the part it's compared against for brevity): 这是我的YANG模型example.yang(为简便起见,我仅粘贴了与之比较的部分):

module example {
    rpc action {
       input {
           leaf param2 {
               type string
           }
           leaf param1 {
               type string
           }
    }
}

yang2dsdl -t rpc example.yang The schemas are generated successfully. yang2dsdl -t rpc example.yang模式已成功生成。

yang2dsdl -s -j -b example -t rpc -v example.xml yang2dsdl -s -j -b示例-t rpc -v example.xml

error: element "param1" not allowed yet; 错误:元素“ param1”尚未被允许; missing required element "param2" 缺少必需的元素“ param2”

Though param1 and param2 are in the input xml file, as they are not in the same order as in YANG model, it throws errors. 尽管param1和param2在输入xml文件中,但是由于它们的顺序与YANG模型中的顺序不同,因此会引发错误。

Can someone tell me how to solve this problem? 有人可以告诉我如何解决这个问题吗?

It seems that the YANG RFC treats order of child elements differently for rpcs and other data. 似乎YANG RFC对于rpcs和其他数据对待子元素的顺序有所不同。 In rpcs the order has to be exactly how it was defined in the model. 在rpcs中,顺序必须与模型中定义的顺序完全相同。 In case of other data the order of child elements is not important. 对于其他数据,子元素的顺序并不重要。

So in your case the rpc input was not prepared according to YANG standard and it should be fixed. 因此,在您的情况下,不是根据YANG标准准备的rpc输入,应将其固定。 The yang2dsdl tool works just fine and you should not expect to have there any "ignore order for rpcs" option. yang2dsdl工具工作正常,您不应期望有任何“忽略rpcs顺序”选项。

rpc XML Mapping Rules rpc XML映射规则

Input parameters are encoded as child XML elements to the rpc node's XML element, in the same order as they are defined within the "input" statement . 输入参数被编码为rpc节点的XML元素的子XML元素, 其顺序与“ input”语句中定义的顺序相同

If the RPC operation invocation succeeded, and no output parameters are returned, the <rpc-reply> contains a single <ok/> element defined in [RFC4741]. 如果RPC操作调用成功,并且没有返回任何输出参数,则<rpc-reply>包含在[RFC4741]中定义的单个<ok />元素。 If output parameters are returned, they are encoded as child elements to the <rpc-reply> element defined in [RFC4741], in the same order as they are defined within the "output" statement . 如果返回输出参数,则将它们编码为[RFC4741]中定义的<rpc-reply>元素的子元素,其顺序与在“ output”语句中定义的顺序相同

container XML Mapping Rules 容器XML映射规则

The container's child nodes are encoded as subelements to the container element. 容器的子节点被编码为容器元素的子元素。 If the container defines RPC input or output parameters, these subelements are encoded in the same order as they are defined within the "container" statement . 如果容器定义RPC输入或输出参数,则这些子元素的编码顺序与在“容器”语句中定义的顺序相同 Otherwise, the subelements are encoded in any order. 否则,子元素将以任何顺序编码。

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

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