public static XMLEvent filterAttributes(StartElement startElement,
            XMLEventFactory ef, String[] attributesToKeep) {

        String tagName = startElement.getName().getLocalPart();
        Iterator nameSpaces = startElement.getNamespaces();
        Iterator it = startElement.getAttributes();
        // Array to include all the attributes to be kept.
        ArrayList<Attribute> attArray = new ArrayList<>();

        while (it.hasNext()) {
            Attribute att = (Attribute) it.next();
            for (String attributeToGet : attributesToKeep) {
                String attName = att.getName().getLocalPart();
                if (attName.equals(attributeToGet)) {
                    // If the attribute is "id" then we need to create a new
                    // attribute with the mapped ID.
                    if (attName.equals("id") && tagName.equals("node")) {
                        Attribute newAtt = ef.createAttribute(new QName("id"), Long.toString(idMap.get(Long.valueOf(att.getValue()))));
                        attArray.add(newAtt);
                        break;
                    } else {
                        attArray.add(att);
                        break;
                    }
                }
            }
        }
        XMLEvent event = ef.createStartElement(
                new QName(tagName), attArray.iterator(), nameSpaces);

        return event;
    }