Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a ATOM-XML representation of my data that is returned via a Spring MVC web service. I'm using JAXB to do the serialization, I have a number of namespaces but I want the default namespace set to Atom with no prefix. Here is what I have so far in package-info.java but the atom prefix is being set to ns3.

@XmlSchema(namespace = com.mycomponay.foo.ATOM_NAMESPACE,
xmlns = { 
    @XmlNs(prefix = "foo", namespaceURI = com.mycomponay.foo.NAMESPACE_FOO),
}, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.mycompany.web;

import javax.xml.bind.annotation.XmlNs;

Also I noticed the namespaces display in chrome but not in Firefox.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
691 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try adding an @XmlNs annotation with prefix "" for the namespace you want to appear as the default.

@XmlSchema(
    namespace = com.mycompany.foo.ATOM_NAMESPACE,
    xmlns = { 
        @XmlNs(prefix = "", namespaceURI = com.mycompany.foo.ATOM_NAMESPACE),
        @XmlNs(prefix = "foo", namespaceURI = com.mycompany.foo.NAMESPACE_FOO)
    }, 
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.mycompany.web;

import javax.xml.bind.annotation.*;

Note:

The namespaces specified in the @XmlSchema annotation are meant to affect the generation of the XML Schema and are not guaranteed to be used when a object model is marshalled to XML. However EclipseLink JAXB (MOXy) and recent versions of the JAXB reference implementation will use them whenever possible.

For More Information


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...