We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Platform : WPF
|
Category : XML Namespaces

Which namespace is used to associate namespace identifiers with element names ? Is there any effect on the attributes ?

There is one more type of namespace declaration that can be used to associate namespace identifiers with element names. This is known as a default namespace declaration which uses the following syntax. xmlns=’<namespace identifier>’

Notice that there is no prefix. When a default namespace declaration is used on an element, all unqualified element names within it’s scope are automatically associated with the specified namespace identifier.

Default namespace declarations, however, have absolutely no effect on attributes. The only way to associate an attribute with a namespace identifier is through a prefix.

Consider the following example.

Here, "student" is from the http://www.develop.com/student namespace while "name" and "rating" are from the default namespace urn:foo. The ’id’ attribute doesn’t belong to a namespace since attributes aren’t automatically associated with the default namespace identifier.

This example also illustrates that you can undeclare a default namespace by simply setting the default namespace identifier back to the empty string as shown in the language element (remember you cannot do this with prefix declarations). As a result, the language element also doesn’t belong to a namespace.

The syntax for default namespaces was designed for convenience but they tend to cause more confusion than their worth. The confusion typically stems from the fact that elements and attributes are treated differently and it’s not immediately apparent that nested elements are being assigned the default namespace identifier. Nevertheless, in the end, choosing between prefixes and default namespaces is mostly a matter of style, except when attributes come into play.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.