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 42What the engine returns
Valid asxs: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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Schema errorsNo matching global declaration for the validation rootThe message you get when the document's namespace and the schema's target namespace disagree.
- NamespacesXML Schema Definition (XSD)The namespace the schema language itself lives in.
- ToolsXSD validatorValidates a document against a schema you supply, which is where this mismatch shows up.
Related terms
- NamespaceA URI that qualifies element and attribute names, so identically-named elements from different vocabularies can coexist in one document.
- XML Schema (XSD)The W3C schema language: a grammar written in XML itself, with datatypes, namespaces and a type system.
- Schema locationAn attribute in an instance document pairing a namespace URI with a URL where a schema for it may be found — a hint, not an instruction.
- ValidA well-formed document that also conforms to a declared grammar — a DTD, an XSD schema or a RELAX NG grammar.
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.