首页 > 编程语言 > 详细

spring xml文件头理解(dto和xsd的区别、xmlns、xmlns:xsi、xsi:schemaLocation)

时间:2021-06-16 16:41:30      阅读:24      评论:0      收藏:0      [点我收藏+]

spring xml文件头理解(dto和xsd的区别、xmlns、xmlns:xsi、xsi:schemaLocation)

<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
  xmlns:task="http://www.springframework.org/schema/task"
	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/aop
	   http://www.springframework.org/schema/aop/spring-aop.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/task
	   http://www.springframework.org/schema/task/spring-task.xsd">
</beans>
  • xsd和dtd的区别是什么?

xsd和dtd是xml文件的两种类型,两种类型的xml文件表达的语义不同,一般来说xsd支持的语义多于dtd。spring解析xml的时候同时支持两种类型的xml文件

  • xmlns是什么意思?xmlns:xsi是什么意思

xmlns的全称是xml namespace,对应中文含义是xml文件命名空间。只有定义了命名空间,才可以在xml中使用对应的标签。其中beans是默认命名空间,所以只用了xmlns,并没有标记namespace前缀;而xmlns:xsi表示的是使用xsi作为前缀的Namespace,需要在文档中进行生命。

  • xsi:schemaLocation

xsi:schemaLocation属性指的是namespace为http://www.w3.org/2001/XMLSchema-instance里面的schemaLocation属性,这里能够使用这个标签的原因是因为我们在一开始就声明了xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"。xsi:schemaLocation定义了xml namespace和对应的XSD(xml schema definition)文档的位置关系。它的值由一个或多个URI引用对组成,两个URI之间以空白符分隔,第一个URI是定义的XML Namespace的值,第二个URI给出的是schema文档的位置,schema处理器将从这个位置读取schema文档,schema文档的targetnamespace必须和第一个URI匹配。xsi:schemaLocation一定是两个成对出现的

  • 补充:xsd的schema文件作用是什么?

作用只有一个:规范xml可以使用的标签范围

  • spring.schema和spring.handler文件的作用?

spring.schema定义了命名空间到xsd的映射关系。spring内部维护了许多版本的xsd文件,spring可以通过spring.schema的映射关系从本地找到xsd,完成xml标签规范的校验,这样的好处是规避了对网络的依赖
spring.handler定义了xsd文件到parse解析器的映射关系,解析器是针对xsd文件唯一存在的,解析器继承自NamespaceHandlerSupport。namespaceHandlerSupport维护了一个map,key是标签名称,value是对应标签的解析器

spring xml文件头理解(dto和xsd的区别、xmlns、xmlns:xsi、xsi:schemaLocation)

原文:https://www.cnblogs.com/deer-hang/p/14889584.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!