一. 首先介紹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命名空間作用:
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】選擇添加:
這樣以后再xml文件里面寫頭就能夠出現只能提示了!!!!!!!!!!!!!!!!!!!!!!!!