首页javajaxbJava HTML/XML - 如何为带有属性的自包含标记写入一个xml注释

Java HTML/XML - 如何为带有属性的自包含标记写入一个xml注释

我们想知道如何为带有属性的自包含标记写入一个xml注释。
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

public class Main {

  public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Type.class);

    Type type = new Type();

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(type, System.out);
  }

  @XmlRootElement
  public static class Type {

    @XmlAttribute
    protected final String res = "http://www.w3.org/2004/02/java2s#ConceptScheme";

  }
}