Skip to main content

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

XSD guide

XSD targetNamespace and elementFormDefault

Predict which instance elements must be namespace-qualified, separate schema vocabulary from target vocabulary, and fix no-declaration validation failures.

9 min read · Updated 2026-08-21

The short answer

targetNamespace assigns the schema's global declarations to a vocabulary namespace. elementFormDefault controls whether locally declared instance elements use that namespace by default: qualified puts them in the target namespace, while unqualified leaves them in no namespace unless an individual declaration overrides the form. Neither setting is created by the xs prefix used to write the schema.

Keep schema language and target vocabulary separate

The xs prefix names XML Schema's own elements such as schema and complexType. targetNamespace names the application vocabulary being declared. A separate prefix such as tns is conventionally bound to that target URI for references between schema components.

Qualified target vocabulary
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="urn:example:orders"
  xmlns:tns="urn:example:orders"
  elementFormDefault="qualified">
  <xs:element name="order">
    <xs:complexType><xs:sequence>
      <xs:element name="id" type="xs:string"/>
    </xs:sequence></xs:complexType>
  </xs:element>
</xs:schema>
Matching instance document
<order xmlns="urn:example:orders"><id>42</id></order>

Apply form rules only to local declarations

Global element declarations belong to the target namespace when one exists. elementFormDefault affects local element declarations nested inside type definitions or model groups; qualified makes their instance names use the target namespace, while the default unqualified form leaves them outside it.

  • Check whether the failing declaration is global or local.
  • Inspect form on the local declaration before the schema-wide default.
  • Compare namespace URI plus local name in the instance.
  • Treat attributeFormDefault as a separate decision for local attributes.

Debug from the root declaration inward

A no-matching-global-declaration error at the root usually means the instance root is in the wrong namespace or the wrong schema set was loaded. Once the root matches, an unexpected local child often reveals an elementFormDefault mismatch.

Validate one minimal instance containing the root and a single local child. Then add the remaining content back in schema order so namespace errors are not mixed with occurrence or sequence failures.

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.