YANG Module Prefix: Local Namespace Alias in Imports

300-435 By islever Editorial Last updated

Short answer

A A YANG prefix is a locally chosen short alias, such as if for the imported ietf-interfaces module, that simplifies namespace-qualified YANG path and type references.

Question

What is a YANG module prefix?
  1. Short alias for namespace in imports Correct Answer
  2. Module name
  3. File name
  4. Version

Key Takeaways

A YANG module prefix is a locally scoped short alias bound to a module's namespace through an import, not the module name, file name, or revision. In import ietf-interfaces { prefix if; }, the alias if lets qualified paths and type references resolve to the imported model without repeating the full module identifier. Option A wins because the prefix can be renamed without changing the module's identity, namespace URI, or revision.

Expert Analysis

A YANG prefix such as if in import ietf-interfaces { prefix if; } is only a locally scoped alias for a namespace, so the short-alias option A holds while module name, file name and revision describe different properties.

The import binding turns if into a namespace alias, not a module identifier

The decisive evidence is the YANG import construct: import ietf-interfaces { prefix if; } does not rename ietf-interfaces; it creates a short, locally scoped token that stands in for that module's namespace when the importing module writes a path or a type reference. The prefix is declared on the import, so its scope is the module that contains the import. A module can choose intf instead of if and the imported model is unchanged; only the spelling of qualified references inside that importer changes. This is why a prefix is best described as an alias for a namespace rather than as a module name, file name or version. The alias exists to keep YANG expressions readable and unambiguous when several imported modules contribute nodes with similar local names. In a path such as /if:interfaces/if:interface, the if portion tells the parser which namespace the interfaces and interface identifiers belong to. The same principle applies to a type reference such as if:interface-ref: the prefix resolves the definition through the import, not through a filename. A prefix is therefore a convenience with semantic force inside YANG references, but it is not the global identity of the model and it does not travel with the module to other importers.

Module name, file name and revision each identify a different artifact layer

If ietf-interfaces is treated as the prefix, the import statement loses its purpose: the full module name remains available as the import target, while the prefix is the shorter token chosen for references. That is the cost of selecting option B. The file-name choice, option C, is no better: a YANG file is commonly named with the module name and revision, such as [email protected], but the filesystem label is an implementation and packaging detail. Tools can load the same module from a different path, and a filename does not resolve a schema node in a YANG path. Option D confuses the revision with the alias: 2018-02-20 identifies a version of the module and supports import by revision, but it cannot replace if in /if:interfaces. Each of these labels points at a real property of a YANG module, which is the trap; the properties are simply not the namespace alias used in imports. The prefix can be changed without altering the module name, the namespace URI, or the revision date, and that independence is what disqualifies B, C and D as definitions of the prefix.

Namespace URI and YANG prefix divide global identity from local shorthand

The conflation to avoid is between the namespace that identifies a module and the prefix that abbreviates it. For ietf-interfaces, the namespace statement supplies a stable URI, typically urn:ietf:params:xml:ns:yang:ietf-interfaces, while the module header chooses a prefix such as if for references within YANG. An importing module may bind another prefix, say intf, to that same URI; both if:interfaces and intf:interfaces can refer to the same model definition in their respective modules. The prefix is not globally registered and need not match the module's own prefix statement. The namespace URI is the identifier that remains stable across importers, serializations and tool runs. A second boundary matters for automation work: an XML instance document uses XML namespace prefixes, and a RESTCONF JSON payload uses module-name qualification rather than the YANG import prefix. Seeing xmlns:if=... in XML or ietf-interfaces:interfaces in JSON does not make if the module name. The YANG prefix belongs to schema expressions such as XPath, augment, uses and type references; the namespace URI belongs to identity. Keeping those layers separate prevents a local shorthand from being mistaken for the model's formal name.

When if rebinds without changing ietf-interfaces, treat it as a YANG prefix alias

A reliable test in YANG work is to ask what else must change when the token changes. If editing prefix if to prefix intf in an import requires only the qualified references in that importing module to be rewritten, and leaves the module name, namespace URI and revision untouched, the token is a prefix. If the change would alter the import target or the globally significant namespace, it is not a prefix. This test also separates YANG prefixes from serialization prefixes: XML namespace prefixes are chosen independently in each document, and JSON encodes namespace-qualified members with the module name. In a YANG tree generated per RFC 8340, a label such as if:interfaces uses a module prefix to show where an external definition comes from; it does not imply that the source file is named if. Carry the same reasoning into pyang or YANG Suite output and into RESTCONF URLs: a prefix in a schema path is a local qualifier, not a path segment or a filename. The if-then rule is simple: rebindable alias means prefix; fixed model identity means module name or namespace; date-based identity means revision.

Official Reference

Exam Strategy

When a question offers module name, file name, revision, and prefix, test each candidate against a concrete import statement. A prefix can be renamed without changing the YANG file or its revision, while the namespace URI and module name remain fixed; that independence is the quick discriminator. Also separate schema prefixes from XML namespace prefixes, which each document chooses independently, and from JSON module-name qualification.

Practice All 300-435 Questions

Access 150 questions with complete answers and detailed explanations.

View Full 300-435 Practice Test →

← Back to 300-435 Study Guide