-3

I am just wondering if there is a simple method to load Java variables (only String) from a XML file, that is like the following. Most of the libraries and methods i read seem to be quite confusing.

<?xml version="1.0" encoding="UTF-8"?>
<registerData>
  <firstname>Max</firstname>
  <lastname>Mustermann</lastname>
  <email>max@mustermann.com</email>
  <company>Max's Mustermänner</company>
</registerData>

Thank you for your help!

Benjamin

twoleggedhorse
  • 4,938
  • 4
  • 23
  • 38
Benjamin
  • 85
  • 1
  • 2
  • 11

1 Answers1

2

You can use JAXB with annotations.

From memory:

@XmlRootElement("registerData")
public class RegisterData {

    @XmlAttribute
    public String firstName;
    ...
}

See http://www.vogella.com/tutorials/JAXB/article.html - marshal = save, unmarshall = load XML.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138