Code Junkie
Code Junkie

Reputation: 7788

@XmlSchema: "annotation type not applicable to this kind of declaration"

2.11 and java7. I'm trying to annotate my package with @XmlSchema as seen below.

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchema;

@XmlSchema(namespace = "http://www.sitemaps.org/schemas/sitemap/0.9",
    elementFormDefault = XmlNsForm.QUALIFIED)
@XmlRootElement(name="urlset")
public class Urlset {

    private String name;

    @XmlElement
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

However I'm getting this compiling error, "annotation type not applicable to this kind of declaration"

Does anybody know why this might be happening happening?

enter image description here

Upvotes: 2

Views: 3870

Answers (1)

Catchwa
Catchwa

Reputation: 5855

The @XmlSchema annotation is a package annotation, so put it in a file called package-info.java, located in the same source directory as Urlset.java, like so:

@XmlSchema(namespace = "http://www.sitemaps.org/schemas/sitemap/0.9",
    elementFormDefault = XmlNsForm.QUALIFIED)

Remove that same annotation from your Urlset class.

Upvotes: 5

Related Questions