XML 模式/命名空间
我经常在 XML 模式文件中看到如下代码。据我了解 xmlns 是定义一个新的命名空间。但是 xmlns 后面的长 URL 真的有必要吗?我的意思是程序、解析器或任何真正调用的东西,例如“http://www.springframework.org/schema/beans”?或者这条线可以简单地像这样:
<beans xmlns="beansNamespace">
这是其中之一
<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
"
>
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
"
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,解析器在看到
时不会转到http://whatever
IETF 建议 XML 命名空间为 URI,但该 URI 不必是 HTTP URI,事实上,它不需要附加任何“网络协议”。它们仅用于识别。
在某些情况下,人们将命名空间 URI 设计为 HTTP URI,并在该 URI 处插入命名空间的人类可读文档。因此,如果人们要访问该地方,他们就会了解该名称空间的模式。但该惯例并未被广泛采用。
另请参阅XML 中的“xmlns”是什么意思?
以及 是什么导致 Web 服务 URL 和命名空间之间存在差异?
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?