Change XmlRootElement annotation name by using binding

543 views Asked by At

I am trying to convert my xsd files to java objects by using jax-b plugin (This plugin reads my xsd files and convert them to models). Since I have two xsd's with Request and Response schema.

In both schemas , I have same root element name i.e XML. Somebody suggested me that instead of creating binding file to overcome the conflicts of having same name, use different names on both xsd's.

I applied the changes. However when my jax-b do marshalling and unmarshalling it converts to the new name I provided.

Example:

REQUEST

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:element name="RequestXML"> 
</xs:schema>

RESPONSE

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:element name="ResponseXML"> 
</xs:schema>

By Jax-b plugin it creates me:

@XmlRootElement(name = "RequestXML")
public class RequestXML


@XmlRootElement(name = "ResponseXML")
public class ResponseXML

Marshalling

<RequestXML>
    <HEADER></HEADER>
    <CUSTOMER></CUSTOMER>
</RequestXML> 

However My request should be

<XML>
    <HEADER></HEADER>
    <CUSTOMER></CUSTOMER>
</XML>

Please suggest me solution. Can I use binding while creating my objects? I dont want to change manually rootElement name to XML

Please reply

0

There are 0 answers