xml文件中,<beans >中的xmlns,xmlns:xsi,xmlns:context,等等

    xiaoxiao2026-03-13  4

    参考文章如下:

    http://bbs.csdn.net/topics/390751819

    ×××××××××××××××××××××分割线×××××××××××××××××××××

    下面的说法是我个人理解,并不一定正确。仅供参考。

    如果有更好的说法,或者理解,欢迎各位大大跟我说,我保证马上更改博客内容。

    写博客的目的就是为了方便技术的交流,和更好的学习,谢谢。

    联系方式QQ:1286238812.

    ×××××××××××分割线×××××××××××××××××××××××

    web.xml中,是<web-app>

    比如 web 2.5的<web-app>是:

    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    在xml文件中,都有一个开头的<beans>

    <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:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">

    xmlns:意思是 xml name space。 这表示默认命名空间

    而 xmlns:xsi 相当于 默认命名空间的一个属性。

    而 xsi:schemaLocation ,应该是xsi的一个属性了。

    而在 xsi:schemaLocation中的引用,都是成对存在的。

    http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd

    如果不是使用本地配置,则需要,先声明 命名空间,然后 空格 然后,指定配置实例  。

    比如:http://www.springframework.org/schema/beans

    会有好多个实例。

    Index of /schema/beans

    Parent Directoryspring-beans-2.0.xsdspring-beans-2.5.xsdspring-beans-3.0.xsdspring-beans-3.1.xsdspring-beans-3.2.xsdspring-beans-4.0.xsdspring-beans-4.1.xsdspring-beans-4.2.xsdspring-beans-4.3.xsdspring-beans.xsdApache/2.2.3 (CentOS) Server at www.springframework.org Port 80

    然后下面,指定需要,3.0。

    当然,这个xsd,也可以在本地配置。

    直接吧xsd配置,放到resources文件夹下。

    然后,指定方式,代码如下:

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/mvc classpath:spring-mvc-4.0.xsd http://www.springframework.org/schema/beans classpath:spring-beans-4.0.xsd http://www.springframework.org/schema/context classpath:spring-context-4.0.xsd http://www.springframework.org/schema/task classpath:spring-task-4.0.xsd http://www.springframework.org/schema/tx classpath:spring-tx-2.5.xsd">

    如果有任何问题或者疑问,欢迎联系我,共同探讨学习共同进步,谢谢。

    ****************分割线*******************************

    补充来源:https://msdn.microsoft.com/zh-cn/magazine/7a99s76a(v=vs.90).aspx

    补充如下:

    xsi:schemaLocation 属性绑定支持

    .NET Framework 3.5 其他版本

    .NET Framework 不为 xsi:schemaLocation 属性提供绑定支持。

    当将 XML 文档反序列化为对象时,XmlSerializer 类忽略 xsi:schemaLocation 属性。

    说明

    schemaLocation 属性是在 XML 架构实例命名空间 http://www.w3.org/2001/XMLSchema-instance(通常与前缀 xsi 关联)中定义的,它仅适用于 XML 实例文档,而不适用于 XML 架构文档。 它与在 XML 架构命名空间 http://www.w3.org/2001/XMLSchema 中定义的 schemaLocation 属性不同。

    xsi:schemaLocation 属性提供一种方法来查找在 XML 实例文档中定义的命名空间的 XML 架构定义。 它的值是用空白分隔的统一资源标识符 (URI) 对的列表,其中的每一对 URI 都依次包含一个命名空间以及该命名空间的 XML 架构定义(通常为 .xsd 文件)的位置。

    当将 XML 文档反序列化为对象时,XmlSerializer 类会忽略 xsi:schemaLocation 属性。 但是,在验证 XML 文档时,XmlValidatingReader 类可以使用该属性值来获取 XML 架构定义。 请参见使用 XmlValidatingReader 对照 XML 架构 (XSD) 进行验证。

    可能的包含元素:任何实例元素

    相关资源:python入门教程(PDF版)
    最新回复(0)