How do I set the xml namespace when using Jersey, jaxb & jax-rs
How do I set开发者_开发问答 the xml namespace when using Jersey, jaxb & jax-rs
This is all done using JAXB annotations. The points below refer to your domain model.
Schema Level
You can specify schema level namespace information using the @XmlSchema package level annotation:
@XmlSchema(namespace = "http://www.example.org",
elementFormDefault = XmlNsForm.QUALIFIED)
package org.example;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
The above annotation leveraging elementFormDefault will default the namespace of all elements to "http://www.example.org".
Type Level
You can override namespaces at the type level using the @XmlType annotation:
@XmlType(namespace="http://www.example.org/foo")
Property/Field Level
And/or you can specify namespace information on the annotations themselves:
- @XmlAttribute(namespace="http://www.example.org/bar")
- @XmlElement(namespace="http://www.example.org/bar")
- @XmlElementWrapper(namespace="http://www.example.org/bar")
- @XmlRootElement(namespace="http://www.example.org/bar")
Example
I have a blog post that demonstrates these concepts with an example:
- http://bdoughan.blogspot.com/2010/08/jaxb-namespaces.html
精彩评论