Search code examples
javajsp-tags

JSP custom tags: missing DTD/XML Schema


I've written my JSP custom tag with the following TLD:

<?xml version="1.0" encoding="UTF-8"?>
<taglib
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"
  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  version="2.1">
  <tlibversion>1.0</tlibversion> 
  <jspversion>2.1</jspversion>
  ...

Now Eclipse Helios complains that "No grammar constraints (DTD or XML schema) detected for the document."

I know how to disable the warning, I was instead wondering how to solve the problem by providing DTD or schema information.

By the way in the above piece of XML I have:

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"

but it doesn't seem to help.

UPDATE on Peter's suggestion I went to check in my Window > Preferences > XML > XML Catalog and I found the following that may fit:

Entry element:  Public
Location:   dtdsAndSchemas/web-jsptaglibrary_1_2.dtd in jar file 
usr/local/eclipse/plugins/org.eclipse.jst.standard.schemas_1.1.0.v201003031644.jar
URI:       jar:file:/usr/local/eclipse/plugins/org
  .eclipse.jst.standard.schemas_1.1.0.v201003031644.jar!/dtdsAndSchemas
  /web-jsptaglibrary_1_2.dtd
Key type:   Public ID
Key:    -//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN

So I tried to add the following to my tld:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">

Now I've the following errors:

Multiple annotations found at this line:

  • Attribute "xsi:schemaLocation" must be declared for element type "taglib".
  • Attribute "version" must be declared for element type "taglib".
  • Attribute "xmlns" with value "http://java.sun.com/xml/ns/javaee" must have a value of "http://java.sun.com/JSP/ TagLibraryDescriptor".

  • schema_reference.4: Failed to read schema document 'web-jsptaglibrary_2_1.xsd', because

    1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

  • The content of element type "taglib" must match "(tlib-version,jsp-version,short-name,uri?,display-name?,small-icon?,large-icon?,description?,validator?,listener*,tag+)".

  • Attribute "xmlns:xsi" must be declared for element type "taglib".

Solution

  • If Eclipse doesn't automatically pick up the XSD from the library, you can always add it manually: Window > Preferences > XML > XML Catalog

    In my case it was already present in the plugin section. It probably came with one of the Eclipse Java EE plugins.