lyd_parse_data_mem behavior
Hi, I'm running into a weird issue with parsing XMLs under certain conditions.
- Create a context and load the models "Cisco-IOS-XE-native" and "Cisco-IOS-XE-mdt-cfg".
- Parse an XML into the context using
lyd_parse_data_memwith only the LYD_PARSE_STRICT flag. - When parsing an XML tree under the
<native>tree ,lyd_parse_data_memreturns a NULL lyd_node. - When parsing an XML tree under the
<mdt-cfg-data>tree ,lyd_parse_data_memreturns a properly populated lyd_node. - When I use the flags LYD_PARSE_STRICT and LYD_PARSE_ONLY, then both
and XMLs get parsed. Also when I explicitly validate these nodes, nothing gets deleted. - When I parse an XML which is a combination of both mdt-cfg-data and native tags, only the mdt config gets parsed whereas native does not.
Example XMLs: MDT XML:
<mdt-config-data xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-mdt-cfg">
<mdt-subscription>
<subscription-id>12345</subscription-id>
<base>
<stream>ABC</stream>
<encoding>XYZ</encoding>
</base>
</mdt-subscription>
<mdt-named-protocol-rcvrs>
<mdt-named-protocol-rcvr>
<name>DEF</name>
<protocol>native</protocol>
</mdt-named-protocol-rcvr>
</mdt-named-protocol-rcvrs>
<proto-grpc-profile>
<name>GHI</name>
</proto-grpc-profile>
<mdt-xfrm>
<name>JKL</name>
</mdt-xfrm>
</mdt-config-data>
NATIVE XML:
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:yang="urn:ietf:params:xml:ns:yang:1" yang:operation="none">
<ip>
<routing-conf>
<routing yang:operation="replace" yang:orig-default="false" yang:orig-value="true">false</routing>
</routing-conf>
</ip>
<interface>
<Vlan>
<name>23</name>
<mac-address yang:operation="replace" yang:orig-default="false" yang:orig-value="2C:3F:0B:00:45:11">2C:3F:0B:00:45:C0</mac-address>
</Vlan>
<Vlan yang:operation="delete">
<name>24</name>
<mac-address>2C:3F:0B:00:45:22</mac-address>
</Vlan>
<Vlan yang:operation="none">
<name>25</name>
<mac-address yang:operation="create">2C:3F:0B:00:45:25</mac-address>
</Vlan>
</interface>
</native>
You should check return values and look at any errors. The behavior you described may be correct so mention what is the behavior you expect and include any error messages.
There are no error messages. Could you explain why the behavior may be correct? Why does the native tree in 3 show up as empty even though we've loaded the correct schema. And why does 5 work when I add the LYD_PARSE_ONLY flag and then validate explicitly?
Please attach the exact YANG modules with all their imports that you are using. I have tried it with some arbitrary revision and there were unknown nodes in both data trees.
We're using the models from https://github.com/YangModels/yang/tree/main/vendor/cisco/xe/17121
Fine, please modify my test to reproduce the exact problem you have. It all behaved as expected for me except using only LYD_PARSE_STRICT does not work, you must use at least LYD_VALIDATE_PRESENT so that the data succeed validation and are parsed.