[Eclipse] How to use local DTDs to validate XMLs

Eclipse content assistance for XMLs is missing for DTD files if internet connection is not available.

By default Eclipse does not support local DTD files. Because of this, many developers loose a privilege of Eclipse; content assistance for parameter/attribute is missing while working with DTD based XML files. However if you are connected to Internet, you will not face this issue.

Here is a tip to show you how to point your Eclipse instance to local DTD files.

1. Add XML Catalogs

First you need to open up the "XML Catalog" dialog by:
Windows -> Preferences -> XML -> XML Catalog
Then click on "Add..." and select "Catalog Entry". For a single local DTD file you need to add one Catalog Entry.

For the location: you need to find DTD file from your local disk.
For the Key: you need to enter the relevant key as per the <!DOCTYPE entry of your XML files.

2. Hibernate Examples Demo

This tip is demoed using Hibernate as an example. Hibernate Configuration DTD and Hibernate Mappings DTD is added locally into Eclipse below. First of all, you need to download and store hibernate jar file somewhere in your local disk; we used hibernate-core-3.6.10.Final version (available here as well as here).

2.1 Hibernate Configuration DTD

DTD file referred by hibernate.cfg.xml file is "hibernate-configuration-3.0.dtd". To point eclipse to that DTD, you need to enter below values and select OK in above "Catalog Entry" screen.


Key: -//Hibernate/Hibernate Configuration DTD 3.0//EN
Location: jar:file:/<path/to/jar>/hibernate-core.jar!/org/hibernate/hibernate-configuration-3.0.dtd

Then Eclipse will create a new Catalog and save with below details.
Entry element:  Public
Location:   org/hibernate/hibernate-configuration-3.0.dtd in jar file opt/libs/hibernate-core.jar
URI:       jar:file:/opt/libs/hibernate-core.jar!/org/hibernate/hibernate-configuration-3.0.dtd
Key type:   Public ID
Key:    -//Hibernate/Hibernate Configuration DTD 3.0//EN

2.2 Hibernate Mappings DTD

DTD file referred by <entity>.hbm.xml file is "hibernate-mapping-3.0.dtd". Same as above step, in "Catalog Entry" screen you need to enter below values and select OK.

Eclipse will create a new Catalog and save with below details.
Entry element:  Public
Location:   org/hibernate/hibernate-mapping-3.0.dtd in jar file opt/libs/hibernate-core.jar
URI:       jar:file:/opt/libs/hibernate-core.jar!/org/hibernate/hibernate-mapping-3.0.dtd
Key type:   Public ID
Key:    -//Hibernate/Hibernate Mapping DTD 3.0//EN

2.3 Results

After creating the Catalogs, you can check this my opening your hibernate.cfg.xml file and trying to open up the DTD file link in the top of the file by "Ctrl + Mouse Over". You will notice that Eclipse prompts two links and one is the local DTD.

Similarly, Eclipse will provide content assistance for XML file editing even when internet connectivity is gone.

3. Conclusion

Using this method, you can create catalogs for any DTD and let Eclipse point to your local DTD files. Hope this helps you.

COMMENTS

BLOGGER: 9
Loading...
Name

About,2,Adsense,3,Ant,1,Apache,3,Axis,3,Blogger,1,Books,1,CentOS,2,Chrome,2,CSS,2,Database,3,Earn Online,3,Eclipse,10,Facebook,1,Firefox,10,Gmail,4,GNU/Linux,9,Google,26,GWT,8,Hardware,2,IE,5,Interesting,15,Internet,14,Java,49,Javascript,7,JBoss,1,Jenkins,1,Log4j,2,Me,6,Microsoft,2,Miscellaneous,1,News,11,Opinion,10,OSGi,1,PHP,1,Productivity,3,Programming,36,Puzzle,3,Security,4,Software,41,Sports,9,Spring,2,Story,6,Subversion,3,TDD,4,Tech,2,Tips,1,Tomcat,6,Tutorial,13,Ubuntu,4,Web application,14,Web Design,2,Web services,3,Windows,10,Yahoo,1,Zip,2,
ltr
item
Digizol: [Eclipse] How to use local DTDs to validate XMLs
[Eclipse] How to use local DTDs to validate XMLs
Eclipse content assistance for XMLs is missing for DTD files if internet connection is not available.
https://2.bp.blogspot.com/-ITXYtNosR9U/UojbClbOqUI/AAAAAAAABEk/x8kw2_WNCvg/s1600/hibernate-eclipse-dtd.gif
https://2.bp.blogspot.com/-ITXYtNosR9U/UojbClbOqUI/AAAAAAAABEk/x8kw2_WNCvg/s72-c/hibernate-eclipse-dtd.gif
Digizol
http://www.digizol.com/2013/11/eclipse-local-dtd-hibernate-example.html
http://www.digizol.com/
http://www.digizol.com/
http://www.digizol.com/2013/11/eclipse-local-dtd-hibernate-example.html
true
7440473
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy