Controlling Qualification
One of the major headaches with DTDs is that they have no explicit support for namespace prefixes since they predate the “Namespaces in XML” recommendation. Although “Namespaces in XML” went to great pains to explain that prefixes were only placeholders and only the namespace URIs really matter, it was painful and awkward to design a DTD that could support arbitrary prefixes. Schemas correct this by validating against namespace URIs and local names rather than prefixed names.
The elementFormDefault
and attributeFormDefault
attributes of the
xs:schema
element control whether
locally declared elements and attributes must be namespace-qualified
within instance documents. Suppose the attribute attributeFormDefault
is set to qualified
in the schema, like this:
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://namespaces.oreilly.com/xmlnut/address" xmlns:addr="http://namespaces.oreilly.com/xmlnut/address" attributeFormDefault="qualified">
Now, if addressdoc.xml is validated against the schema, the validator reports the following error:
Attribute "language" must be declared for element type "fullName".
Since the default attribute form has been set to qualified
, the schema processor doesn’t
recognize the unqualified language
attribute as belonging to the
same schema as the fullName
element. This is because attributes, unlike elements, don’t inherit
the default namespace from the xmlns="...
" attribute. They must always be explicitly ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.