[英]Yang model validation error. Element not allowed anywhere, expected end-tag
I have the following YANG model.我有以下YANG model。 I want to validate the model against custom xml data.我想根据自定义 xml 数据验证 model。
module turing-machine {
namespace "http://example.net/turing-machine";
prefix "tm";
description
"Data model for the Turing Machine.";
revision 2013-12-27 {
description
"Initial revision.";
}
/* State data and Configuration */
container turing-machine {
list router {
config false;
leaf name {
type string;
}
leaf interface {
type string;
}
}
}
}
The xml I want to validate is:我要验证的 xml 是:
<?xml version="1.0" encoding="utf-8"?>
<!-- file: turing-machine-config.xml -->
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<turing-machine xmlns="http://example.net/turing-machine">
<router>
<name>A</name>
</router>
<router>
<interface>B</interface>
</router>
</turing-machine>
</config>
The validation is done using the following commands:使用以下命令完成验证:
yang2dsdl -t config model.yang
trang -I rng -O rnc model-config.rng model-config.rnc
yang2dsdl -s -j -b model -t config -v data.xml
The validation results in:验证结果为:
Element `router` not allowed anywhere, expected element end-tag.
Please note that since the child elements are not common inside router and therefore I cannot use a 'config true' because I cannot choose a key, I think that a workaround is to use config false.请注意,由于子元素在路由器内部并不常见,因此我无法使用“config true”,因为我无法选择密钥,我认为解决方法是使用 config false。
The problem is that config is used instead of data inside the xml and inside the validation commands.问题是在 xml 和验证命令中使用了配置而不是数据。 A valid xml is:一个有效的 xml 是:
<?xml version="1.0" encoding="utf-8"?>
<!-- file: turing-machine-config.xml -->
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<turing-machine xmlns="http://example.net/turing-machine">
<router>
<name>A</name>
</router>
<router>
<interface>B</interface>
</router>
</turing-machine>
</data>
Then in order to validate the following commands must be executed.然后为了验证必须执行以下命令。 Note that -t data is optional since data is the default option anyway.请注意, -t data 是可选的,因为 data 无论如何都是默认选项。
yang2dsdl -t data model.yang
trang -I rng -O rnc model-config.rng model-config.rnc
yang2dsdl -s -j -b model -t data -v data.xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.