Frizz
Frizz

Reputation: 2544

XML Schemas / Namespaces

I often see code like the one below in XML schema files. As far as I understood xmlns is to define a new namespace. But are the long URLs that follow a xmlns really necessary? I mean does the program, parser, whatever really make a call to, e.g. "http://www.springframework.org/schema/beans"? Or could the line simply like this here:

<beans xmlns="beansNamespace">

Here's one of the

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
"
>

Upvotes: 4

Views: 390

Answers (1)

Cheeso
Cheeso

Reputation: 192467

No, the parser does not go to http://whatever, when it sees
<element xmlns='http://whatever...'>

The IETF recommends that XML namespaces be URIs, but that URI need not be an HTTP URI, and in fact it need not have any "network protocol" attached to it. They are used for identification only.

In some cases people design namespace URIs as HTTP URIs, and they insert human-readable documentation for the namespace at that URI. so if a human were to visit the place, they'd learn about the schema with that namespace. But that convention is not widely adopted.

See also, What does "xmlns" in XML mean?
and, What causes a difference between a web service URL and a namespace?

Upvotes: 6

Related Questions