I am writing a code that reads data from an XML returned by hardware, but some TAG
now has not and can not check the existence of it.
Follow the code used to read the XML and use the data.
public void lerXml(String xml) {
String xmlFilePathNFe3 = xml;
JAXBContext context = null;
CFe cfe = null;
try {
context = JAXBContext.newInstance(CFe.class.getPackage().getName());
Unmarshaller unmarshaller1 = context.createUnmarshaller();
cfe = (CFe) unmarshaller1.unmarshal(new File(xmlFilePathNFe3));
} catch (JAXBException ex) {
ex.printStackTrace();
}
String exemploCpf = cfe.getInfCFe().getDest().getCPF();
.....
But if TAG
<CPF>
does not exist return Nullpointer
exception how to check if there is the relevant information.