So I have the following issue when trying to build an xml from java class using jaxb. My first tag needs to be like this :
<Entity Type=‘test-instance’>
Some xml
</Entity>
I need the first tag to have something written in it but the closing one needs to have only Entity.
I created a claas and added @XMLRootElement tag with name=Entity and using this I have the correct last tag. If I use the whole expression I have in both first and closing tag which does not help me.
I added a String variable with @XMLAttribute so I can add something else after Entity. The problem is if I initialize the variable with value, I will get the String double quotes. For example
@XMLAttribute(name=“Type”)
String x = “test-instance”;
When I build this it will read :
<Entity Type=“test-instance”>
, with double quotes and I need only single quotes.
If use the whole description I need in the xml attribute, for example :
@XMLAttribute(name=“Type=‘test-instance’”)
String x;
This will work fine but if the variable is not initialized then it won’t add anything and if write something like String x=“”; Then I will get :
<Entity Type=‘test-instance’=“”>
So I cannot get rid of the quotes which are coming from my String.
I was thinking something to either hardcode the first Entity tag and to have the last one where I close it different but couldn’t find anything.
Or the other option to set the XMLAttribute even if the String is not initialized.I saw something on the XMLElement that had something like “required” but it’s not available for XMLAttribute and I’m not really sure it does what I need it to.
Any help would be gratefully appreciated.
Thanks