class RrdpParser {

    public Notification notification(final InputStream inputStream) {
        try {
            final XMLInputFactory factory = XMLInputFactory.newInstance();
            final XMLEventReader eventReader = factory.createXMLEventReader(inputStream);

            String sessionId = null;
            BigInteger serial = null;
            String snapshotUri = null;
            String snapshotHash = null;
            final List<DeltaInfo> deltas = new ArrayList<>();

            while (eventReader.hasNext()) {
                final XMLEvent event = eventReader.nextEvent();

                if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    final StartElement startElement = event.asStartElement();
                    final String qName = startElement.getName().getLocalPart();

                    switch (qName) {
                        case "notification":
                            serial = new BigInteger(getAttr(startElement, "serial", "Notification serial is not present"));
                            sessionId = getAttr(startElement, "session_id", "Session id is not present");
                            break;
                        case "snapshot":
                            snapshotUri = getAttr(startElement, "uri", "Snapshot URI is not present");
                            snapshotHash = getAttr(startElement, "hash", "Snapshot hash is not present");
                            break;
                        case "delta":
                            final String deltaUri = getAttr(startElement, "uri", "Delta URI is not present");
                            final String deltaHash = getAttr(startElement, "hash", "Delta hash is not present");
                            final String deltaSerial = getAttr(startElement, "serial", "Delta serial is not present");
                            deltas.add(new DeltaInfo(deltaUri, deltaHash, new BigInteger(deltaSerial)));
                            break;
                    }
                }
            }
            return new Notification(sessionId, serial, snapshotUri, snapshotHash, deltas);
        } catch (XMLStreamException e) {
            throw new RrdpException("Couldn't parse notification: ", e);
        }
    }

}