Can anyone please explain the difference between UnMarshaller and Parser in JAXB. I have read like UnMarshaller is used to retrieve the value from XML document. Parser also does the same thing. Anyone please explain the difference.
eg:consider the below example zoo.xml
<zoo>
<zooName>Vandalur Zoo</zooName>
<zooId>12321</zooId>
<animals>
<animal>
<animalName>Lion</animalName>
<animalType>Wild</animalType>
</animal>
Using UnMarshaller,
JAXBContext jaxbContext = JAXBContext
.newInstance("com.javapapers.xml.jaxb");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<?> zoo = (JAXBElement<?>) unmarshaller
.unmarshal(new FileInputStream("zoo.xml"));
ZooInfo zooInfo = (ZooInfo) zoo.getValue();
Using parser:
File fXmlFile = new File("zoo.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);