XML Namespace XMLNS Value

Hi, all!

I have been watching a few videos on XML tables and I mostly understand them. However, I am unclear on one point: How is Is the value in the attribute xmlns assigned? Is it the the coder that makes it up based on arbitrarity? Does the coder look it up from a master table? (How that would be achieved is anyone’s guess.) Is there a convention that coders tend to follow, e.g., the value begins with a set URL, e.g., “http://www.w3.org/” but is concatenated with a coder-determined URL phrase, e.g., “TR/html4/”?

In an example, it looks like in pseudocode, the coder uses an arbitrary value, e.g.,

xmlns:h = “http://www.w3.org/” + “TR/html4/”
xmlns:f = “http://www.mnogojazyk.info

I have also seen examples in which the xmlns attribute’s value ends with a forward slash and examples in which the xmlns attribute’s value ends without the forward slash. Which is it or does it matter and under what circumstances?

Many thanks.

The following is an excerpt from XML Namespaces

Note: The namespace URI is not used by the parser to look up information.

The purpose of using an URI is to give the namespace a unique name.

However, companies often use the namespace as a pointer to a web page containing namespace information.

The emphasis in the above should be on unique and the use of the word often or rather “sometimes”.

In other words, there is no hard requirement in what value you use, as long as it is unique.

A URL is a globally unique address, so that generally makes for a safe unique way of distinguishing an XML namespace as unique to other namespaces, to ensure there is no element name conflicts during parsing. But note, that URL does not even need to be a working address.

Note: When a URL is used in XML namespaces, it is then referred to as a URI.

It is good practice to include the namespace of established URI’s, such as those used for XSLT or specific types or versions of HTML.

In addition, when working with an API that employs XML, e.g., SOAP, then you should use the namespaces dictated by the API.

But if you’re designing, creating and using the XML yourself, end-to-end, than you don’t even need to use namespaces (which can really simplify your parsing logic). When you do this, just ensure that each element name you define can uniquely identify a specific information “type”, e.g., <clientCity /> vs. <contactCity />

What I describe in the above paragraph is known as a custom XML vocabulary and is quite common.

For further reading, see: XML namespace - Wikipedia

I hope that helps.