I agree with using JAXB. As JAXB is a spec you can choose from multiple implementations:
Here is how you can do it with JAXB:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class APIResponce {
private Integer userid;
private Integer uuid;
}
When used with the follow Demo class:
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(APIResponce.class);
File xml = new File("input.xml");
Unmarshaller unmarshaller = jc.createUnmarshaller();
APIResponce api = (APIResponce) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(api, System.out);
}
}
Will produce the following XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml>
<userid>123456</userid>
<uuid>123456</uuid>
</xml>