mavi mavi - 4 months ago 6
Java Question

Error in JAXB unMarshaller?

i am getting the following while reading from my .xml is the error

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"teacher"). Expected elements are (none)

And here is my file.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Teacher xmlns="" Id="0001" />

main class

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class convertorDemo {
public static void main(String[] args) {

try {

File file = new File("C:\\file.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Teacher.class);

Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Teacher mrS= (Teacher ) jaxbUnmarshaller.unmarshal(file);

} catch (JAXBException e) {


and here is some other details

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@XmlType(name = "Teacher", propOrder = {
public class Teacher{

@XmlAttribute(name = "Id")
protected String Id;

public String getId() {
return Id;

public void setId(String value) {
this.Id = value;


I don't know what my problem is and i am new to JAXB.please help!!


Annotate your Tana class with XmlRootElement.