Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header Tag in XML using JAXB

Tags:

java

jaxb

Right now I am getting this as an XML output from my JAXB Marshaller

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><create></create>

But I want my root element as:

<create xmlns="http://ws.abc.com" xmlns:doc="http://ws.abc.com">

Do I need to modify this using parsers, Or is there any annotation available.

like image 770
Sunny Gupta Avatar asked Jan 18 '12 05:01

Sunny Gupta


People also ask

How to read XML file using JAXB?

To read XML, first get the JAXBContext . It is entry point to the JAXB API and provides methods to unmarshal, marshal and validate operations. Now get the Unmarshaller instance from JAXBContext . It's unmarshal() method unmarshal XML data from the specified XML and return the resulting content tree.

What is marshaller and unmarshaller in Java?

Marshalling is the process of transforming Java objects into XML documents. Unmarshalling is the process of reading XML documents into Java objects. The JAXBContext class provides the client's entry point to the JAXB API.

What is marshalling XML?

Object/XML Mapping, or O/X mapping for short, is the act of converting an XML document to and from an object. This conversion process is also known as XML Marshalling, or XML Serialization. This chapter uses these terms interchangeably.


1 Answers

You can set the following property on the Marshaller to remove the header:

marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

For More Information

  • http://blog.bdoughan.com/2011/08/jaxb-and-java-io-files-streams-readers.html
like image 173
bdoughan Avatar answered Oct 23 '22 13:10

bdoughan