2013-10-12 71 views
2

如何可以解析这样的事情:没有孩子的根元素。 JAXB

<?xml version="1.0"> 
<response>1</response> 

+2

使用@XmlValue - 见http://stackoverflow.com/questions/1496052/what-is-the-jaxb换算对的一文本节点值 – lreeder

回答

0

你可以有:

@XmlRootElement 
@XmlAccessorType(XmlAccessType.FIELD) 
public class Response { 

    @XmlValue 
    private int value: 

} 

或者你可以这样做:

Integer response = unmarshaller.unmarshal(xml, Integer.class).getValue();