Element (@NotNull XMLStreamReader2 reader, boolean isNsSupported, @NotNull SafeJdomFactory factory) { Element element = factory.element(reader.getLocalName(), isNsSupported ? Namespace.getNamespace(reader.getPrefix(), reader.getNamespaceURI()) : Namespace.NO_NAMESPACE); // handle attributes int attributeCount = reader.getAttributeCount(); if (attributeCount != 0) { AttributeList list = element.initAttributeList(attributeCount); for (int i = 0; i < attributeCount; i++) { list.doAdd(factory.attribute( reader.getAttributeLocalName(i), reader.getAttributeValue(i), isNsSupported ? Namespace.getNamespace(reader.getAttributePrefix(i), reader.getAttributeNamespace(i)) : Namespace.NO_NAMESPACE )); } } if (isNsSupported) { // handle namespaces for (int i = 0, len = reader.getNamespaceCount(); i < len; i++) { element.addNamespaceDeclaration(Namespace.getNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i))); } } return element; }