Hi here are the classes you need to do this:
1 -
package xml;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class XMLReader {
public static void main(String[] args) {
try {
File file = new File("Path to DataFile.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(HiModel.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
HiModel hiModel = (HiModel) jaxbUnmarshaller.unmarshal(file);
System.out.println(hiModel.getName());
System.out.println(hiModel.getValue());
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
2 - package xml;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "string")
public class HiModel {
private String name;
private String value;
public HiModel() {
}
public String getName() {
return name;
}
@XmlAttribute(name = "name")
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
@XmlAttribute(name = "value")
public void setValue(String value) {
this.value = value;
}
}
3 -