【转载】关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
原文在:
https://yq.aliyun.com/articles/40353
这里有转载:http://www.cnblogs.com/zhao1949/p/5652167.html
先来一段Spring的XML样本,相信大家都很眼熟: <?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
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">
<context:component-scan base-package="xxx.xxx.controller" /> <context:annotation-config/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/> <mvc:resources mapping="/images/**" location="/images/" /> <bean id="xxx" class="xxx.xxx.xxx.Xxx">
<property name="xxx" value="xxxx"/>
</bean>
</beans>
这 个文档中,根元素<beans/>就不用说了,接下来是xmlns。那么什么是xmlns呢?xmlns其实是XML Namespace的缩写,可译为“XML命名空间”,但个人觉得,翻译后的名字反而不好理解,所以我们就叫它为XML Namespace吧。 为什么需要xmlns,避免重名
如何使用xmlns xmlns:context="http://www.springframework.org/schema/context" <context:component-scan base-package="xxx.xxx.controller" />
xmlns和xmlns:xsi有什么不同?
xmlns表示默认的Namespace。例如Spring XML文档中的
xmlns="http://www.springframework.org/schema/beans"
这一句表示该文档默认的XML Namespace为http://www.springframwork.org/schema/beans。对于默认的Namespace中的元素,可以不使用前缀。例如Spring XML文档中的
|
1
2
3
|
<bean id="xxx" class="xxx.xxx.xxx.Xxx"> <property name="xxx" value="xxxx"/></bean> |
xsi:schemaLocation有何作用? xsi:schemaLocation属性其实是Namespace为http://www.w3.org/2001/XMLSchema-instance里的schemaLocation属性,正是因为我们一开始声明了 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
第一个URI是定义的 XML Namespace的值,第二个URI给出Schema文档的位置,Schema处理器将从这个位置读取Schema文档,该文档的targetNamespace必须与第一个URI相匹配。例如: xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
http://www.springframework.org/schema/context/spring-context.xsd。这里我们可以打开这个Schema的位置,下面是这个文档的开始部分: <xsd:schema xmlns="http://www.springframework.org/schema/context"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tool="http://www.springframework.org/schema/tool" <!-- 这里的targetNamespace和上方xsi:schemaLocation中的第一个URI匹配 -->
targetNamespace="http://www.springframework.org/schema/context"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
Done!
【转载】关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation的更多相关文章
- 操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP)
原文:操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP) 不管是用 PHP 还是 C#, 在操作 XML 的时候我们除了一个节点一个节点去取值之外, 还有一个非常方便的表达式, 就是 ...
- XML文档中的xmlns、xmlns:xsi和xsi:schemaLocation
文章转载自:https://yq.aliyun.com/articles/40353 相信很多人和我一样,在编写Spring或者Maven或者其他需要用到XML文档的程序时,通常都是将这些XML文档头 ...
- 关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
https://yq.aliyun.com/articles/40353 ************************************* 摘要: 相信很多人和我一样,在编写Spring或者 ...
- 关于"XML 文档(2, 2)中有错误:不应有 <xml xmlns=''>"错误
XML文件名 <?xml version="1.0" encoding="utf-8"?> <Config xmlns:xsi="h ...
- [XML] C# XmlHelper操作Xml文档的帮助类 (转载)
点击下载 XmlHelper.rar 主要功能如下所示 /// <summary> /// 类说明:XmlHelper /// 编 码 人:苏飞 /// 联系方式:361983679 // ...
- (转载)将一段符合XML格式规范字符串插入已有XML文档当中
想我们已经存在一个XML文档,结构如下: < xmlversion="1.0"encoding="utf-8">< employees&g ...
- Android XML文档解析(一)——SAX解析
---------------------------------------------------------------------------------------------------- ...
- C# 使用XmlDocument类对XML文档进行操作
原创地址:http://www.cnblogs.com/jfzhu/archive/2012/11/19/2778098.html 转载请注明出处 W3C制定了XML DOM标准.很多编程语言中多提供 ...
- dom4j解析xml文档全面介绍
一.dom4j介绍 dom4j是一个Java的XML API,类似于jdom,用来读写XML文件的.dom4j是一个非常非常优秀的Java XML API,具有性能优异.功能强大和极端易用使用的特点, ...
随机推荐
- PostgreSQL数据库中获取表主键名称
PostgreSQL数据库中获取表主键名称 一.如下表示,要获取teacher表的主键信息: select pg_constraint.conname as pk_name,pg_attribute. ...
- 平面最小割—BZOJ 1001
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 很有意思的题目,本来想直接上网络流,但是发现点太多,边太多2333. 直接网络流无法 ...
- Codeforces Round #266 (Div. 2) D
D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Ambient Occlusion
一般在光照模型中,ambient light的计算方法为:A = l * m,其中l表示表面接收到的来自光源的ambient light的总量,而m表示表面接收到ambient light后,反射和吸 ...
- MM1排队系统
#coding=utf-8 import time import random as rd #import math import pylab as pl def simulate(nameda,u) ...
- 用wget实现cookie欺骗
用wget实现cookie欺骗 . 分析登录界面的html代码 页面在 http://bbs.linuxeden.com/ <form. id="loginform" met ...
- cf 383 D
D. Antimatter time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- maven编译时候报"编码 GBK 的不可映射字符"
决这个问题的思路: 在maven的编译插件中声明正确的字符集编码编码——编译使用的字符集编码与代码文件使用的字符集编码一致!! 安装系统之后,一般中文系统默认字符集是GBK.我们安装的软件一般都继承使 ...
- CF A. Xenia and Divisors
题目大意: n(为三的倍数)个数的一个序列(每个数均不大于7),找出a,b,c a能被b整除,b能被c整除,序列中的每个数都被用到. 1 2 3 4 5 6 7 只有 1 2 4 1 2 6 1 3 ...
- hdu 4159 Indomie (DP,数学概率)
推出数学公式: #include<stdio.h> #include<string.h> __int64 C(int m,int n) { __int64 tmp=; if(m ...