2 XML schema

来源:互联网 发布:树莓派的编程语言 编辑:程序博客网 时间:2024/06/04 19:40

以spring配置为例子:

<?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"            xmlns:mvc="http://www.springframework.org/schema/mvc"         xmlns:tx="http://www.springframework.org/schema/tx"      xmlns:aop="http://www.springframework.org/schema/aop"      xmlns:context="http://www.springframework.org/schema/context"      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.xsd                http://www.springframework.org/schema/context                 http://www.springframework.org/schema/context/spring-context.xsd                http://www.springframework.org/schema/mvc                http://www.springframework.org/schema/mvc/spring-mvc.xsd              http://www.springframework.org/schema/tx               http://www.springframework.org/schema/tx/spring-tx.xsd              http://www.springframework.org/schema/aop              http://www.springframework.org/schema/aop/spring-aop.xsd "      default-autowire="byName">  </beans>

一 <?xml version="1.0" encoding="UTF-8"?> 这是xml本身的声明,表示这是一个xml文档

二 beans:xml的一个元素,你也可以叫做sb lowb(随便你怎么叫)

三 xmlns="http://www.springframework.org/schema/beans" :表示beans元素的默认命名空间,本质上所有的元素都应该长成这个样子:<bean:xxx> <tx:xxx> <aop:xxx> ,现在你写成了<bean>,那就表示是默认的命名空间里面的元素名称 。

xmlns的作用:就是给一组元素名称一个统一的名称,用于区别其他的名称。

四 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" :这个一个叫做xsi的命名空间,但是这个命名空间是一个标准,使用xsi的属性schemaLocation来给命名空间赋值,这个值就是xsd文件的位置

五 xis:schemaLocation:由一个或多个URI引用对组成,第一个uri是前面定义的url,第二个uri是uri对应的xsd文档的位置。两个url之间以空格或者换行隔开

六 default-autowire是默认命名空间的属性值,也就是http://www.springframework.org/schema/beans这个里面的属性

七 第四条纯属个人理解,我觉得xsi:schemaLocation就是起到了一个赋值的作用。(如果有更好的标准解释,求告知)

原创粉丝点击