XML interview question · Most asked
Explain XML namespaces and the default namespace.
Summary
A namespace gives element and attribute names a globally unique identity: a URI plus a local name. xmlns:p="uri" binds a prefix; xmlns="uri" sets a default namespace for unprefixed elements in scope. Prefixes are just shorthand: two documents with different prefixes for the same URI mean the same thing. Unprefixed attributes are in no namespace.
Longer Answer
The URI is an identifier, not a download location. In code, names are often written in Clark notation, {uri}local.
Key Points
- Name = URI + local name.
- Prefix binding vs default namespace.
- Prefixes don't matter, URIs do.
- Unprefixed attributes: no namespace.
Deep dive: XML Tutorial: XML Namespaces
Explanation
What interviewers look for
The default-namespace and attribute subtleties.
More most-asked XML questions
- What's the difference between well-formed and valid XML?
- Compare DOM, SAX and StAX (or pull parsing).
- Your XPath query returns nothing, but the elements are clearly there. What's the likely cause?
- What is an XXE attack and how do you prevent it?
- How does XSLT work? Explain templates and apply-templates.
- How would you process a 10 GB XML file?
- What is XML and where is it still used today?
- Which characters must be escaped in XML, and what is CDATA?