I have the following YANG model. I want to validate the model against custom xml data.
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 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.
The problem is that config is used instead of data inside the xml and inside the validation commands. A valid xml is:
<?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.
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