spring servlet xml 顶部的声明到底意味着什么?
我在 struts 、 spring 、 ibatis 等中遇到过许多 xml 配置。我曾经盲目地使用该声明,因为我无知。我真的很想知道这个声明有什么用处,它的用途是确认 DTD 吗?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
I have come across many xml configurations in struts , spring , ibatis etc. i used to use the declaration blindly coz im ignorant. I really want to know how this declarations are useful, is the one use being confirming to the DTD ?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的意思是:
xmlns="http://www.springframework.org/schema/beans"
和xmlns:xsi="http://www.w3.org/2001/XMLSchema -instance"
这是名称空间。
线
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
是关于在哪里可以找到名称空间声明。来自评论:
假设您有两个不同的 XSD 模式,并且希望在 XML 中使用它们。并且它们都定义了一个名称相同但含义不同的标签。然后,读取 XML 文件的程序需要了解您所指的两个标签中的哪一个。这就是前缀 (
xsi
) 的用途。完整的东西用于验证和编辑器支持(自动完成)。但也适用于在不了解具体语义的情况下处理 XML 的人员。 (例如 XLST。)
If you mean:
xmlns="http://www.springframework.org/schema/beans"
andxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
this are name spaces.
the line
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
is about where the name space declaration can be found.From the comments:
Assume you have two different XSD schemata that you want to use both in your XML. And both of them define a tag with the same name, but different meaning. Then an program that read your XML file need to understand which of the both tags you mean. So that is what the prefix (
xsi
) or what ever is used for.The complete thing is used for validation, and editor support (auto completion). But also for stuff that is proceeding the XML without knowledge about the concrete semantics. (XLST for example.)