想要編寫xml文件時代碼提示,其實只要配置了相應的xsd文件即可,xsd文件也就是xml文件的一個約束。就是決定了你xml文件中可以寫哪些東西。
xsd文件是xml文件的元數據文件。
以bean標簽為例:
你編寫<bean>標簽的時候沒有提示,則可以配置pring-beans-3.0.xsd這個文件到xml頭信息中
1
2
3
4
5
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
直接在spring壓縮包中找到相應的xsd文件,在eclipse中配置下即可。
配置方式:
上圖key的值應該和
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
xsi:schemaLocation="http://www.springframework.org/schema/beans
這個文件中的http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 一樣
但是我怎么知道這個key該填寫什么路徑呢?
分析這個鏈接:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
瀏覽器中打開:http://www.springframework.org/schema/
出現如下界面
假如你想配置bean的提示,那就點擊beans鏈接
點擊選擇相應的版本。
點擊了之后地址欄的地址為:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
頁面上打印的信息也就是spring-beans-3.0.xsd文件的內容
總結:
1、在eclipse的XML catalog中配置相應的xsd文件
2、在xml文件的頭信息中配置相應的key,這樣在編寫xml文件的時候就可以去讀取xsd文件,來約束當前xml文件中可以寫哪些內容
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
spring2.5和spring3.0各個不同的版本,其xsd文件位置也不同。
spring2.5 xsd文件位置:在src源代碼相應模塊的config目錄下
..\spring-framework-2.5.6\src\org\springframework\aop\config\spring-aop-2.5.xsd
spring3.0 xsd文件位置:由於spring3.0之后的版本是按各個模塊來分包的,所以在其projects目錄中
..\spring-framework-3.0.0.RELEASE\projects\org.springframework.aop\src\main\resources\org\springframework\aop\config\spring-aop-3.0.xsd