简体   繁体   English

如何使用JAXB生成没有XML根元素的XML文档

[英]How to use JAXB to generate XML document without XML root element

Sometimes I would like to generate the XML document like this: 有时我想生成这样的XML文档:

<?xml version="1.0" encoding="utf-8"?>
<properties>
</properties>
<context>
</context>

Do not with root elment, not like this: 不要与root elment,不是这样的:

 <?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. 你想要的不是有效的XML。 So neither JAXB nor any other technologie can produce a "document" like this. 因此,JAXB和任何其他技术都无法生成这样的“文档”。

According to the Well-formedness of an XML: 根据XML的良构性:

There is a single "root" element that contains all the other elements. 有一个“root”元素包含所有其他元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM