- Java后端 學習路線 筆記匯總表【黑馬程式員】
- XML學習筆記01【xml_基礎、xml_約束】【day01】
- XML學習筆記02【xml_決議】【day01】
目錄
01 xml_基礎
今日內容
xml_概述
xml_快速入門
xml_組成部分
屬性串列——encoding
指令:結合css
文本:CDATA區
XML 元素、XML 命名規則
02 xml_約束
xml_約束概述
xml_約束_dtd
xml_約束_schema
student.xml
student.xsd
application_mvc.xml
01 xml_基礎
今日內容
- XML
- 概念
- 語法
- 決議
xml_概述
概念:Extensible Markup Language 可擴展標記語言
* 可擴展:標簽都是自定義的, <user> <student>* 功能
* 存盤資料
1. 組態檔
2. 在網路中傳輸
* xml與html的區別
1. xml標簽都是自定義的,html標簽是預定義,
2. xml的語法嚴格,html語法松散
3. xml是存盤資料的,html是展示資料* w3c:World Wide Web Consortium,萬維網聯盟
xml_快速入門
語法:
* 基本語法:
1. xml檔案的后綴名 .xml
2. xml第一行必須定義為檔案宣告
3. xml檔案中有且僅有一個根標簽
4. 屬性值必須使用引號(單雙都可)引起來
5. 標簽必須正確關閉(單標簽,自閉和:<hr/>)
6. xml標簽名稱區分大小寫
* 快速入門:代碼...
* 組成部分
<?xml version="1.0" encoding="UTF-8" ?><!--版本資訊1.0-->
<users><!--根標簽-->
<user id='1'><!--自己定義的標簽,想寫啥 就寫啥-->
<name>zhangsan</name>
<age>23</age>
<sex>male</sex>
</user>
<user id='2'>
<name>lisi</name>
<age>24</age>
<sex>female</sex>
</user>
</users>
<!--
檢驗xml檔案的正確性:
xml可以被所有的瀏覽器所決議,瀏覽器中有對應的xml決議引擎
將xml拖拽進瀏覽器,瀏覽器不報錯,則xml書寫正確!
-->
xml_組成部分
組成部分:
1. 檔案宣告
1. 格式:<?xml 屬性串列 ?> (‘?’與‘<’、‘>’之間不能有空格)
2. 屬性串列:
* version:版本號,必須的屬性(xml第1版就是1.0,1.1版本不向下兼容,主流仍為1.0版)
* encoding:編碼方式,告知決議引擎 當前檔案使用的字符集,默認值:ISO-8859-1
* standalone:是否獨立
* 取值:
* yes:檔案獨立,不依賴其他檔案
* no:檔案不獨立,依賴其他檔案
2. 指令(了解):結合css
* <?xml-stylesheet type="text/css" href="a.css" ?>
3. 標簽:標簽名稱 自定義
* 規則:
* 名稱可以包含字母、數字以及其他的字符
* 名稱不能以數字或者標點符號開始
* 名稱不能以字母 xml(或者 XML、Xml 等等)開始
* 名稱不能包含空格4. 屬性:
* 由鍵值對構成,用引號(單雙引號)引起來
* id屬性值唯一
5. 文本:
* CDATA區:在該區域中的資料會被原樣展示
* 格式: <![CDATA[ 資料 ]]>
屬性串列——encoding
指令:結合css
文本:CDATA區
XML 元素、XML 命名規則
02 xml_約束
xml_約束概述
* 約束:規定xml檔案的書寫規則
* 作為框架的使用者(程式員):
1. 能夠在xml中引入約束檔案
2. 能夠簡單的讀懂約束檔案
xml_約束_dtd
* 分類:
1. DTD:一種簡單的約束技術,
2. Schema:一種復雜的約束技術,* DTD:
* 引入dtd檔案到xml檔案中
* 內部dtd:將約束規則定義在xml檔案中
* 外部dtd:將約束的規則定義在外部的dtd檔案中
* 本地:<!DOCTYPE 根標簽名 SYSTEM "dtd檔案的位置"> :SYSTEM表示系統本地
* 網路:<!DOCTYPE 根標簽名 PUBLIC "dtd檔案名字" "dtd檔案的位置URL">
xml_約束_schema
* Schema:
* 引入:
1.填寫xml檔案的根元素
2.引入xsi前綴. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3.引入xsd檔案命名空間. xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"
4.為每一個xsd約束宣告一個前綴,作為標識 xmlns="http://www.itcast.cn/xml"
<students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.itcast.cn/xml"
xsi:schemaLocation="http://www.itcast.cn/xml student.xsd">
student.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!--
1.填寫xml檔案的根元素
2.引入xsi前綴. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3.引入xsd檔案命名空間. xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"
4.為每一個xsd約束宣告一個前綴,作為標識 xmlns="http://www.itcast.cn/xml"
-->
<students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.itcast.cn/xml"
xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"
>
<student number="heima_0001">
<name>tom</name>
<age>18</age>
<sex>male</sex>
</student>
</students>
student.xsd
<?xml version="1.0"?>
<xsd:schema xmlns="http://www.itcast.cn/xml"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.itcast.cn/xml" elementFormDefault="qualified">
<xsd:element name="students" type="studentsType"/>
<xsd:complexType name="studentsType">
<xsd:sequence>
<xsd:element name="student" type="studentType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="studentType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="age" type="ageType" />
<xsd:element name="sex" type="sexType" />
</xsd:sequence>
<xsd:attribute name="number" type="numberType" use="required"/>
</xsd:complexType>
<xsd:simpleType name="sexType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="male"/>
<xsd:enumeration value="female"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="ageType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="256"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="numberType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="heima_\d{4}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
application_mvc.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:annotation-config />
<context:component-scan base-package="cn.cisol.mvcdemo">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="htm" value="text/html" />
</map>
</property>
<property name="defaultViews">
<list>
<bean
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
</bean>
</list>
</property>
<property name="ignoreAcceptHeader" value="true" />
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsps/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="209715200" />
<property name="defaultEncoding" value="UTF-8" />
<property name="resolveLazily" value="true" />
</bean>
</beans>
趕緊學,加油~
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/258681.html
標籤:其他
上一篇:安裝docker及常見錯誤解決
下一篇:隨筆小記


















