开发者

XML Schemas / Namespaces

开发者 https://www.devze.com 2023-03-04 11:21 出处:网络
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,

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开发者_如何学Python.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
"
>


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号