1. 程式人生 > >MyEclipse中XML的智慧提示和關於Spring 配置檔案頭的一些記錄和解釋

MyEclipse中XML的智慧提示和關於Spring 配置檔案頭的一些記錄和解釋

轉載:http://www.cnblogs.com/gagayt/p/3603232.html

一. 首先介紹XML檔案的一些知識:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 

xmlns:context="http://www.springframework.org/schema/context" 

xmlns:p="http://www.springframework.org/schema/p" 

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"

</beans>


XML Schema名稱空間作用(xml namespace-----xmlns):
1、避免命名衝突,像Java中的package一樣

2、將不同作用的標籤分門別類(像Spring中的context名稱空間針對元件的標籤)


程式碼解釋:
1、xmlns="http://www.springframework.org/schema/beans"
宣告xml檔案預設的名稱空間,表示未使用其他名稱空間的所有標籤的預設名稱空間。

2、xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

宣告XML Schema 例項,聲明後就可以使用 schemaLocation 屬性了

3、xmlns:aop="http://www.springframework.org/schema/mvc"
宣告字首為mvc的名稱空間,後面的URL用於標示名稱空間的地址不會被解析器用於查詢資訊。其惟一的作用是賦予名稱空間一個惟一的名稱。當名稱空間被定義在元素的開始標籤中時,所有帶有相同字首的子元素都會與同一個名稱空間相關聯。

4、xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
這個從命名可以看出個大概,指定Schema的位置這個屬性必須結合名稱空間使用。這個屬性有兩個值,第一個值表示需要使用的名稱空間。第二個值表示供名稱空間使用的 XML schema 的位置


所以我們需要什麼樣的標籤的時候,就引入什麼樣的名稱空間和Schema 定義就可以了。

二. 如何在MyEclipse中進行匯入呢:

首先選擇:【Window】-->【Preferences】-->【MyEclipse】-->【Files and Editors】-->【XML】-->【XML Catalog】選擇新增: