JAXB unMarshaller 出错?
Error in JAXB unMarshaller?
我在阅读我的 .xml 时得到以下信息 file.here 是错误
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.dJohn.com/teacher", local:"teacher"). Expected elements are (none)
这是我的 file.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Teacher xmlns="http://www.dJohn.com/teacher" Id="0001" />
主要class
import java.io.File;
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) {
e.printStackTrace();
}
}
}
这是Teacher.java..留下一些其他细节
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@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;
}
}
我不知道我的问题是什么,我是新手JAXB.please求助!!
用 XmlRootElement
注释您的 Tana
class。
我在阅读我的 .xml 时得到以下信息 file.here 是错误
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.dJohn.com/teacher", local:"teacher"). Expected elements are (none)
这是我的 file.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Teacher xmlns="http://www.dJohn.com/teacher" Id="0001" />
主要class
import java.io.File;
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) {
e.printStackTrace();
}
}
}
这是Teacher.java..留下一些其他细节
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@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;
}
}
我不知道我的问题是什么,我是新手JAXB.please求助!!
用 XmlRootElement
注释您的 Tana
class。