forum

Home / DeveloperSection / Forums / class field become a tag name using JAXB

class field become a tag name using JAXB

Anonymous User198316-Oct-2014

I am using Java and JAXB for XML processing.

I have the following class:

    publicclassCharacteristic {
 
        privateString characteristic;
        privateString value;
 
        @XmlAttribute
        publicString getCharacteristic() {
            return characteristic;
        }
 
        publicvoid setCharacteristic(String characteristic) {
            this.characteristic = characteristic;
        }
 
        @XmlValue
        publicString getValue() {
            return value;
        }
 
        publicvoid setValue(String value) {
            this.value = value;
        }
    }
 
    publicstaticvoid main(String[] args) {
        Characteristic c = newCharacteristic();
        c.setCharacteristic("store_capacity");
        c.setValue(40);
        Characteristic c2 = newCharacteristic();
        c2.setCharacteristic("number_of_doors");
        c2.setValue(4);
    }

This is the result that I get:

<characteristicscharacteristic="store_capacity">40</characteristics>
<characteristicscharacteristic="number_of_doors">4</characteristics>

I want to get the following result:

<store_capacity>40</store_capacity>
<number_of_doors>4</number_of_doors>

How can I achieve this?


Updated on 16-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By