Sometimes I would like to generate the XML document like this:
<?xml version="1.0" encoding="utf-8"?>
<properties>
</properties>
<context>
</context>
Do not with root elment, not like this:
<?xml version="1.0" encoding="utf-8"?>
<root>
<properties>
</properties>
<context>
</context>
</root>
Here is my Class:
//@XmlRootElement(name="root")
public class WithoutRootElement {
private String properties;
Private String context;
@XmlElement(name="properties")
public String getProperties() {...}
@XmlElement(name="context")
public String getContext() {...}
}
How to do this?
What you want is not valid XML. So neither JAXB nor any other technologie can produce a "document" like this.
According to the Well-formedness of an XML:
There is a single "root" element that contains all the other elements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.