Skip to content
uencoder
TASK

Parse XML with namespaces

XML namespaces qualify element names to avoid collisions. Learn the xmlns declaration, default vs prefixed namespaces, and how to parse them correctly.

  1. 1

    XML namespaces use URIs to disambiguate element names. A namespace is declared with xmlns="uri" (default) or xmlns:prefix="uri" (prefixed). Elements are then qualified: <prefix:element>. The namespace URI is the identifier — the prefix is just a shorthand. Two elements with the same local name but different namespaces are different elements.

  2. 2
    XML Formatter →

    Format the XML to see namespace declarations clearly. The formatter shows which prefixes map to which URIs. Verify that all prefixed elements have a corresponding xmlns declaration in scope.

  3. 3
    JSON XML Converter →

    Convert namespaced XML to JSON. Namespace-qualified elements typically become prefixed keys: <ns:element> → "ns:element" or "{uri}element" depending on the converter. Understand your converter's namespace handling to query the correct keys.

  4. 4

    Common namespaces: xmlns="http://www.w3.org/1999/xhtml" (XHTML), xmlns:svg="http://www.w3.org/2000/svg" (SVG), xmlns:atom="http://www.w3.org/2005/Atom" (Atom feeds). When parsing, match on the namespace URI, not the prefix — prefixes can be reassigned. Use XPath with namespace resolvers for robust querying.

Frequently asked questions

Why use namespaces?
To combine XML vocabularies without name collisions. For example, XHTML and SVG both have a <title> element — namespaces distinguish <xhtml:title> from <svg:title>. Without namespaces, a parser cannot tell them apart.
Is the prefix significant?
No — the namespace URI is the identifier, not the prefix. <foo:bar xmlns:foo="urn:x"> and <baz:bar xmlns:baz="urn:x"> are the same element. When comparing or querying, always use the URI, not the prefix. Prefixes are arbitrary shorthand.

Workflows that solve this

Learn more

Want to understand why?

Related tools