350-401 Practice Question: A network engineer is using a Python script with the ncclient library to retrieve…
A network engineer is using a Python script with the ncclient library to retrieve configuration from a Cisco IOS XE device via NETCONF. The script uses the <get-config> RPC with a source of <running/> and a filter of <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"/>. The script successfully retrieves the configuration but the output is in XML format. The engineer wants to convert this XML into a Python dictionary for easier manipulation. Which Python library is specifically designed to parse XML into a dictionary structure?
⚠ Common exam trap
Candidates often confuse general XML parsing libraries with a library that specifically outputs a dictionary.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
xmltodict
xmltodict is specifically designed to convert XML into a Python dictionary, making it the ideal choice for transforming NETCONF XML responses into a manipulable dictionary format.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
ElementTree
Why it's wrong here
ElementTree is part of the Python standard library for parsing XML into a tree structure. It does not convert XML to a dictionary; it provides an ElementTree object. To get a dictionary, the engineer would need to traverse the tree and build one manually. It is not specifically designed for dictionary conversion.
- ✗
lxml
Why it's wrong here
lxml is a powerful XML and HTML parsing library that provides ElementTree-like APIs, but it does not directly convert XML to a dictionary. It is used for parsing and navigating XML trees, not for dictionary conversion. While it can be used to build a dictionary manually, it is not specifically designed for that purpose.
- ✗
BeautifulSoup
Why it's wrong here
BeautifulSoup is designed mainly for parsing HTML and messy markup, for example in web scraping, and builds a tree you navigate with find() and find_all(). It can read XML with a suitable parser, but it does not produce a Python dictionary. For converting structured NETCONF XML into dictionaries in one call, xmltodict is the purpose-built tool, while ElementTree and lxml suit tree navigation and XPath.
- ✓
xmltodict
Why this is correct
xmltodict.parse() turns an XML document into nested Python dictionaries in one call: elements become keys, repeated elements become lists, and attributes appear as keys prefixed with '@'. With ncclient, parse reply.data_xml and navigate with keys such as data['data']['native']['hostname']. Watch for single-item lists, which come back as dictionaries unless 'force_list' is used, and use unparse() to build XML.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 350-401 question from scratch — 1,923 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
You might also like
Similar 350-401 questions
- A network engineer is troubleshooting an automated configuration change that caused a routing loop. The change was pushe…
- Which TWO statements about NETCONF and YANG are true?
- A network engineer is learning about data models used in network automation. The engineer needs to choose a data modelin…
- A network architect is designing a Python script that will retrieve interface statistics from a Cisco IOS XE device usin…
- A network engineer is using the YANG Suite tool to explore YANG models supported by a Cisco IOS XE device. The engineer…
Written and reviewed by Johnson Ajibi, MSc IT Security
Security Systems Architect · founder of Courseiva
Last reviewed September 2026 · checked against the official Cisco exam blueprint
This 350-401 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 350-401 exam.