日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

xml中xsd、xsi、xmlns的含义

發(fā)布時間:2023/12/29 综合教程 35 生活家
生活随笔 收集整理的這篇文章主要介紹了 xml中xsd、xsi、xmlns的含义 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Maven的pom.xml文件頭信息如下:
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
 其中,xmlns的值是默認(rèn)的命名空間;
xmlns:xsi的值是以xsi為前綴的標(biāo)簽屬性的命名空間,xsi:schemaLocation就是該命名空間下的屬性;
xsi:schemaLocation的值是xml文件書寫需要遵循的xsd約束,它包括兩部分:前面是xsd文件對應(yīng)的命名空間,后面是xsd文件的地址。

打開地址http://maven.apache.org/xsd/maven-4.0.0.xsd"包含如下頭信息:
<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://maven.apache.org/POM/4.0.0"
elementFormDefault="qualified"
targetNamespace="http://maven.apache.org/POM/4.0.0">
targetNamespace表示該xsd只對該目標(biāo)命名空間生效,即xsd文件對應(yīng)該命名空間。在pom.xml中使用xsi:schemaLocation引入xsd文件的時候,在xsd文件的前面就是該xsd對應(yīng)的命名空間。

在一個xml文件中可以定義多個命名空間,比如在springmvc-servlet.xml文件中,它的文件頭信息如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
springmvc-servlet.xml的每個命名空間對應(yīng)不同的xsd約束文件。如圖1,以命名空間為前綴的標(biāo)簽/屬性受該命名空間對應(yīng)的xsd文件約束。

圖1 spring-servlet.xml中的多個命名空間

再回到pom.xml文件中。xml文件中頭信息中包含的xmlns:xsi可以看出,該xml文件可以看成是受xml-schema-instance的約束,xml-schema-instance就是xsd。在http://maven.apache.org/xsd/maven-4.0.0.xsd中,文件頭信息xmlns:xs="http://www.w3.org/2001/XMLSchema"表明xsd文件受xml-schema文件約束。如下圖所示:
xml-Schema → xml-schema-instance(xsd)→ xml 注: “→“”表示約束關(guān)系

這在“https://www.w3.org/TR/xmlschema-1/#ref-xml-namespaces”里也有描述:
The purpose ofXML Schema: Structuresis to define the nature of XML schemas and their component parts, provide an inventory of XML markup constructs with which to represent schemas, and define the application of schemas to XML documents.
The purpose of anXML Schema: Structuresschema is to define and describe a class of XML documents by using schema components to constrain and document the meaning, usage and relationships of their constituent parts: datatypes, elements and their content and attributes and their values. Schemas may also provide for the specification of additional document information, such as normalization and defaulting of attribute and element values. Schemas have facilities for self-documentation. Thus,XML Schema: Structurescan be used to define, describe and catalogue XML vocabularies for classes of XML documents.

xml的約束有兩種方式,除了上面提到的xsd,還有dtd約束文件。在mybatis-config.xml中就使用的dtd約束,它的文件頭信息如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "http://mybatis.org/dtd/mybatis-3-config.dtd" "mybatis-3-config.dtd" >

總結(jié)

以上是生活随笔為你收集整理的xml中xsd、xsi、xmlns的含义的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。