Question: Parsing <rpc-reply> and traversing the resulting lyd_node
Hi,
I have a question about how to parse an
I have an rpc:
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<interface>
<GigabitEthernet>
<name>1/0/5</name>
</GigabitEthernet>
</interface>
</native>
</filter>
</get>
And the resulting
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:9015b7e6-b478-4215-9814-448f64b77d0f">
<data>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<interface>
<GigabitEthernet>
<name>1/0/5</name>
<logging>
<event>
<link-status/>
</event>
</logging>
<access-session>
<host-mode>multi-auth</host-mode>
</access-session>
<cdp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-cdp">
<tlv>
<app-config>
<app>true</app>
</app-config>
<app/>
<server-location/>
<location/>
</tlv>
</cdp>
<cts xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-cts">
<role-based>
<enforcement/>
</role-based>
</cts>
</GigabitEthernet>
</interface>
</native>
</data>
</rpc-reply>
I am parsing this rpc-reply into an lyd_node using
lyd_parse_op () the output of which is an lyd_node
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<data>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<interface>
<GigabitEthernet>
<name>1/0/5</name>
<logging>
<event>
<link-status/>
</event>
</logging>
<access-session>
<host-mode>multi-auth</host-mode>
</access-session>
<cdp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-cdp">
<tlv>
<app-config>
<app>true</app>
</app-config>
<app/>
<server-location/>
<location/>
</tlv>
</cdp>
<cts xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-cts">
<role-based>
<enforcement/>
</role-based>
</cts>
</GigabitEthernet>
</interface>
</native>
</data>
<filter>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<interface>
<GigabitEthernet>
<name>1/0/5</name>
</GigabitEthernet>
</interface>
</native>
</filter>
</get>
When I try to run a DFS traversal of this tree, I get only 3 nodes:
<get>
.....
</get>
<data>
.....
</data>
<filter>
.....
</filter>
I'm unsure of why this is the case. Ideally, I'd like to be able to traverse the entire output tree and be able to access nodes like:
<role-based>
<enforcement/>
</role-based>
How can I go about getting a complete DFS traversal of the resulting data tree?
Thanks !
If you look at the YANG schema structure of the RPC output, those are the nodes that DFS traverses. To access anydata or anyxml data tree, you need to manually cast those nodes into struct lyd_node_any and access their nested tree, which then can again be traversed using DFS.
If @rabhat31 is who I think he is (my coworker), then the approach you described here helped us properly parse the underlying yang data from the RPC wrapper. If that's the case - can we close this issue?