I have created a very basic XML for understanding JAXB Concept. This is the XML File
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<Abc>
<Module> India </Module>
</Abc>
The Java Class created is,
package oracle.ERP.Cloud.Client2;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
//Below annotation defines root element of XML file
@XmlRootElement
public class Abc{
private String Module;
public String getModule() {
System.out.println("Hi");
return Module;
}
@XmlElement
public void setModule(String Module) {
this.Module = Module;
}
}
Java file for Unmarshalling is
package oracle.ERP.Cloud.client2;
import java.io.File;
import java.io.PrintStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import oracle.ERP.Cloud.Client2.Abc;
import oracle.ERP.Cloud.client.Country;
public class JAXBXMLToJava {
public static void main(String Args[]) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(new Class[]{oracle.ERP.Cloud.Client2.Abc.class});
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
File XMLFile = new File("C:\\Users\\NRENTALA\\Desktop\\Analysis\\AbcXML.xml");
oracle.ERP.Cloud.Client2.Abc summary = oracle.ERP.Cloud.Client2.Abc)unmarshaller.unmarshal(XMLFile);
System.out.println("Country Name is : "+ summary.getModule());
}
catch(JAXBException e) {
e.printStackTrace();
}
}
}
When I try to compile this I am getting this error
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Abc"). Expected elements are <{}abc>
Please help me in finding out what is the problem?? Trying this for the first time.