Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple namespace package info Java

I have this package info

/**
 * Created by mflamant on 13/02/2017.
 */
@javax.xml.bind.annotation.XmlSchema(namespace = "namespace1", xmlns = {@XmlNs(prefix = "ns4", namespaceURI = "namespace1")}, elementFormDefault = XmlNsForm.QUALIFIED)

package com.cisco.adt.portal.data.model.API.Equipment;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;

But I want to have 2 namespaces, but I tried to do this:

/**
 * Created by mflamant on 13/02/2017.
 */
@javax.xml.bind.annotation.XmlSchema(namespace = "namespace1", xmlns = {@XmlNs(prefix = "ns4", namespaceURI = "namespace1")}, elementFormDefault = XmlNsForm.QUALIFIED)
@javax.xml.bind.annotation.XmlSchema(namespace = "namespace2", xmlns = {@XmlNs(prefix = "ns4", namespaceURI = "namespace2")}, elementFormDefault = XmlNsForm.QUALIFIED)

package com.cisco.adt.portal.data.model.API.Equipment;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;

But I have an error: "Duplicate annotation", is this possible to have 2 namespaces or not ?

Thank You.

like image 419
Kraven Avatar asked Feb 13 '17 12:02

Kraven


People also ask

What is Package-info Java in JAXB?

package-info. java is a way to apply java annotations at the package level. In this case Jaxb is using package-level annotations to indicate the namespace, and to specify namespace qualification for attributes (source). Follow this answer to receive notifications.

What goes in Package-info Java?

The package-info. java is a Java file that can be added to any Java source package. It is used to provide info at a "package" level as per its name. It contains documentation and annotations used in the package.

How do you create a package-info class?

In IntelliJ IDEA, we can right-click on the package and select New-> package-info. java: Eclipse's New Java Package option allows us to generate a package-info.


1 Answers

You can have two name spaces but not with the same prefix.

Instead of use the annotation into your class, I suggest to add package-info.java file in the package where your model are.

For example, once I built a sitemap, there I needed to add more namespaces, because of strict checking rules of google search console.

Inside the package-info.java file I added more namespaces with the following syntax.

@XmlSchema(
    xmlns = { 
        @XmlNs(prefix = "video", namespaceURI = "http://www.google.com/schemas/sitemap-video/1.1"),
        @XmlNs(prefix = "", namespaceURI = "http://www.sitemaps.org/schemas/sitemap/0.9")
    }
)

/*
 * xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
 * xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
 */

package com.example.myapplication.model.sitemap.pojo;

import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;
like image 86
freedev Avatar answered Sep 18 '22 12:09

freedev