I am trying to parse a pacs.003 ISO20022 formatted xml file. I have the XSD for this and using XMLBeans have created the required Java classes. The problem I am having is that I am not able to read an element from the XML and keep getting a NullPointerException. I have searched for similar problems but most result in the OP moving to a different technology.
The XML snippet I have from LON_20160208.xml is:
<S2SDDDnf:FIToFICstmrDrctDbt xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.003.001.02">
<GrpHdr>
<MsgId>DDA160802AASW006543</MsgId>
</GrpHdr>
</S2SDDDnf:FIToFICstmrDrctDbt>
My code is:
public static void main(String[] args) {
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setUseDefaultNamespace();
xmlOptions.setSavePrettyPrint();
Document doc;
try {
doc = Document.Factory.parse(new File("data_samples/LON_20160208.xml"));
String messageId = doc.getFIToFICstmrDrctDbt().getGrpHdr().getMsgId();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The doc.getFIToFICstmrDrctDbt()
above results in a NullPointerException and this seems to point to either the get_store()
method within the XMLBeans classes or an issue with the namespaces.
I have tried using a substitute namespace map and have toggled the setUseDefaultNamespace()
method on and off (it is currently not commented out above). I have also read an answer regarding adding elementFormDefault="qualified"
to the xsd:schema
element but this has already been done. None of these seem to fix the issue and I am running out of ideas.
Any help would be greatly appreciated.
The Apache POI project has unretired the XMLBeans codebase and is maintaining it as a sub-project. Until now the XMLBeans codebase was held in the Apache Attic where former Apache projects are kept for the public good. Some bug fixes (for a more complete list of changes see CHANGES.txt or JIRA).
The XMLBeans API also allows you to reflect into the XML schema itself through an XML Schema Object model. A cursor model through which you can traverse the full XML infoset. Support for XML DOM. For a more complete introduction, see the XMLBeans Overview or Getting Started With XMLBeans .
When parsing XML files using XMLBeans 2.6.0 or below, the underlying parser created by XMLBeans could be susceptible to XML External Entity (XXE) attacks. This issue was fixed a few years ago but on review, we decided we should have a CVE to raise awareness of the issue.
The xmlbeans-<version>.jar is in the xmlbeans\build directory. Try ant -projecthelp to see other build options. Building on Unix/Linux/Mac or Cygwin is essentially the same as for Windows:
I have been able to fix the issue. It was due to the fact that the message is a more specific SEPA DNF file which is not a generic pacs.003 file. This means it needed a different schema.
The null messages were because the xml does not have a <Document>
root tag, it is a <MPEDDDnfBlkDirDeb>
root tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With