Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Names and namespaces

Target namespace

The namespace a schema's declarations belong to, named by the targetNamespace attribute on xs:schema.

A schema declares components — elements, attributes, types — and targetNamespace says which namespace those components land in. A document is then validated against the schema whose target namespace matches the namespace of its root element. Get this wrong and validation fails with a message about no matching declaration, which reads as though the element is unknown when in fact it is known in a different namespace.

A schema with no targetNamespace declares components in no namespace at all. That is the right choice for an unnamespaced vocabulary and the wrong one for everything else, and it is the most common cause of a schema that appears to validate nothing.

Defined in
XSD 1.0 §3.1
Category
Names and namespaces
Also written
targetNamespace

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • xsi:schemaLocation is only a hint: a document pointing at a schema that does not exist still parses.

    document.xml
    <x xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://example.invalid/nope.xsd">hi</x>

    What the engine returns

    Well-formed.
  • Validation happens only when a schema is supplied — and then the type is what decides.

    schema.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="v" type="xs:integer"/>
    </xs:schema>
    value
    42

    What the engine returns

    Valid as xs:integer.

What catches people out

  • elementFormDefault="qualified" is nearly always what you want alongside a target namespace; without it, only top-level elements are in the namespace and local ones are not.
  • A schema with no targetNamespace validates only unnamespaced documents, however correct the element names look.
  • The instance document's xsi:schemaLocation pairs a namespace URI with a location. Supplying the location alone does nothing.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.