xavierzhao
xavierzhao

Reputation: 799

How to use JAXB to generate XML document without XML root element

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?

Upvotes: 0

Views: 480

Answers (2)

Alexander
Alexander

Reputation: 3245

According to the Well-formedness of an XML:

There is a single "root" element that contains all the other elements.

Upvotes: 0

user647772
user647772

Reputation:

What you want is not valid XML. So neither JAXB nor any other technologie can produce a "document" like this.

Upvotes: 2

Related Questions