@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (rootStarted) { super.startElement(uri, localName, qName, attributes); } else if (usedNamespaceURISet == null) { super.startElement(uri, localName, qName, attributes); rootStarted = true; } else { Set<String> ignoringQNameSet = new HashSet<String>(); for (int i = 0; i < attributes.getLength(); i++) { String attrQName = attributes.getQName(i); if (attrQName.startsWith("xmlns:") && !"xmlns:sv".equals(attrQName)) { String namespaceURI = attributes.getValue(i); if (!usedNamespaceURISet.contains(namespaceURI)) { ignoringQNameSet.add(attributes.getQName(i)); } } } FilteredOutDelegatingAttributes filteredOutAttributes = new FilteredOutDelegatingAttributes(attributes, ignoringQNameSet); super.startElement(uri, localName, qName, filteredOutAttributes); rootStarted = true; } } };