XML自动提示功能

以Sprin0为例 用eclipse,在导入相应的包后(有人说不导包也有提示,因为默认的eclipse导入了jdk的包),eclipse会有代码提示功能。 那么XML文件能不能也这样呢?其实也是可以的,只不过导包的地方不一样。下面以spring为例(虽然Myeclipse6.5中已经集成了,这里只是示范说明)。

进入:window -> Preference... -> MyEclipse ->Files and  Editors -> XML ->XML Catalog选择:选中“User Specified Entries”,点击“Add...”按钮

填入:

URI: 请选择本地文件系统上SPRING_HOME\dist\resources\spring-beans-2.0.xsd 文件

KeyType:选择SchemaLocation

Key: http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

点击确定

将spring配置文件关闭再重新打开即可。可以使用MyEclipse XML Editor打开这些xml文件。在Eclipse3.3以后的版本有些已经集成了,不需要添加。

自动提示的原理:

在spring.jar中有个目录为META-INF,下面有个文件为spring.schemas,打开这个文件一看内容就知道,它把URL映射到了classpath。

例如第一行:

http\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd

这个文件告诉spring容器到某个classpath下去寻找schema文件,而这些文件的确就在spring.jar的相应目录下。

相关推荐