我在 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">
最佳答案
如果你的意思是: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">
是关于可以找到 namespace 声明的位置。
来自评论:
why do we give them like that? is it for the xml syntax validation only? or some other extra purposes?
假设您有两个不同的 XSD 模式,您想在 XML 中同时使用它们。并且它们都定义了一个名称相同但含义不同的标签。然后,读取您的 XML 文件的程序需要了解您的意思是这两个标签中的哪一个。所以这就是前缀(
xsi
)或曾经用于的东西。完整的东西用于验证和编辑器支持(自动完成)。但也适用于在不了解具体语义的情况下处理 XML 的内容。 (例如 XLST。)
关于xml - spring servlet xml 顶部的声明是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8048786/