【问题标题】:XML Schemas / NamespacesXML 模式/命名空间
【发布时间】:2011-05-09 19:49:27
【问题描述】:

我经常在 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
"
>

【问题讨论】:

标签: xml xsd xml-namespaces


【解决方案1】:

不,解析器在看到http://whatever 时不会转到&lt;element xmlns='http://whatever...'&gt;

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?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-03
  • 2012-04-24
  • 2016-05-12
  • 1970-01-01
  • 1970-01-01
  • 2014-11-10
  • 2014-05-26
相关资源
最近更新 更多