I have about 100 (if not more) Java classes generated from a big XSD file via xjc.
That XSD file has upper-case names for its elements. Now, when I marshall one object from these generated Java classes, I have a few issues.
Sample XML produced by JAXB marshall:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<advertiser xmlns:ns2="http://p.t.com/service">
<ns2:Name>TEST Adv 001</ns2:Name>
</advertiser>
The names of the elements (but not those of the sub-elements) are produced by JAXB in lower-case. I need them to be upper-case (as they are in the XSD).
There are some strange ns2: prefixes to the names of the elements e.g. I want the xmlns:ns2 in this example to become just xmlns, and the ns2:Name to become just Name. One answer here on SO suggested putting attributeFormDefault="unqualified" in the XSD, but seems that didn't help me either.
How can I solve these two issues?
I looked here for similar question but don't find one quite identical to mine. Also the answers there look pretty complicated and they ask to change the Java classes which I cannot do. Why should this be so complicated?!
Note that my Java classes are auto-generated, so I don't want to change them manually.
I wonder why the XSD says one thing, and the JAXB marshall process produces another thing. Shouldn't the JAXB marshall generate XML which is 100% compliant with the XSD?
Edit
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Advertiser", propOrder = {
})
public class Advertiser {
@XmlElement(name = "TelID")
protected Integer telID;
@XmlElement(name = "Name")
protected String name;
@XmlElementRef(name = "Address", namespace = "http://p.t.com/service", type = JAXBElement.class)
protected JAXBElement<String> address;
.............
Edit 2
Advertiser adv = new Advertiser();
adv.setName("TEST Adv 001");
StringWriter sw = new StringWriter();
JAXB.marshal(adv, sw);
System.out.println(sw.toString());