2011-05-09 175 views
4

我经常在XML模式文件中看到类似下面的代码。据我了解,xmlns是定义一个新的命名空间。但是,遵循xmlns的长URL是非常必要的吗?我的意思是程序,解析器,真正打个电话,例如“http://www.springframework.org/schema/beans”?或者可以在线路简单,问题是:XML模式/命名空间

<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 
" 
> 
+0

可能重复http://stackoverflow.com/questions/5758041/why-are-urls-in-xml - 名称空间) – skaffman 2011-05-09 11:50:43

回答

6

没有,分析器不会去http://whatever之一,当它看到
<element xmlns='http://whatever...'>

The IETF recommends that XML namespaces be URIs,但该URI不需要是HTTP URI,实际上它不需要附加任何“网络协议”。它们仅用于识别。

在某些情况下,人们将名称空间URI设计为HTTP URI,并在该URI处为命名空间插入人类可读的文档。所以如果一个人访问这个地方,他们会了解这个名字空间的模式。但是该公约并未被广泛采用。

参见,What does "xmlns" in XML mean?
和,What causes a difference between a web service URL and a namespace?

的[为什么在XML命名空间的网址?(
+1

这也是值得阅读詹姆斯克拉克的命名空间教程在http://www.jclark.com/xml/xmlns.htm – 2011-05-09 15:49:33

+0

谢谢Cheeso :) – Frizz 2011-05-09 16:52:36