Use this when working with XML elements.
Elements
XML elements are the tagged building blocks of a document, such as <hostname>r1</hostname>, which can contain text, attributes and child elements in a tree.
1. Elements form the XML tree (<name>value</name>).
2. Must be properly nested and closed.
3. Namespaces qualify names.
4. Order can matter.
5. Empty elements <x/>.
element → children → text
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as encoding/BOM issues, delimiter/quoting ambiguity, duplicate keys, namespace drift, scalar coercion, invalid schema assumptions and parser success without consumer-valid semantics, choosing the cases most relevant to well-formed element structure, namespace-qualified names, nesting/content model and preserving text/attribute distinctions.
Step 2 Common mistakes Narrow the fault
- Ignoring namespaces when searching.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Elements form the XML tree.
- They contain text, attributes and child elements.
- Namespaces apply to element names.
xmllint --xpath 'count(//element)' file.xml— element count- Element names and nesting — structure
- Namespace prefixes — qualification
ReferenceWhy it matters1 section · depth on demand
What it is
XML elements are tagged nodes (<name>value</name>) with attributes and namespaces; NETCONF uses XML.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Elements are the building blocks of XML: a start tag, content and end tag (<name>USERS</name>), or a self-closing tag (<enabled/>). Elements nest to form a tree, and their order can be significant.
import xml.etree.ElementTree as ET
root = ET.parse("vlans.xml").getroot()
for v in root.iter("vlan"):
print(v.get("id"), v.findtext("name"))
new = ET.SubElement(root, "vlan", id="30"); ET.SubElement(new, "name").text = "VOICE"
ET.ElementTree(root).write("vlans.xml", encoding="utf-8", xml_declaration=True)
Element names are case-sensitive, special characters in text must be escaped (<, &), and empty elements can mean "present" in protocols like NETCONF (<confirmed/>).
Mechanics
The linked authority for bounded mechanics is W3C — Extensible Markup Language (XML) 1.0; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in XML > Elements. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.w3.org/TR/xml/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For well-formed element structure, namespace-qualified names, nesting/content model and preserving text/attribute distinctions, prefer typed fields and stable IDs over human presentation text.