private void startElement()

in nbxml/src/main/java/org/apache/vysper/xml/sax/impl/XMLParser.java [361:431]


    private void startElement() throws SAXException {
        log.trace("StartElement {}", qname);

        // check if this should restart stream
        if (restartsAllowed && needsRestart() && qname.equals(restartQname)) {
            restart();
        }

        if (elements.isEmpty()) {
            startDocument();
        }

        // find all namespace declarations so we can populate the NS resolver
        Map<String, String> nsDeclarations = new HashMap<String, String>();
        for (Entry<String, String> attribute : attributes.entrySet()) {
            if (attribute.getKey().equals("xmlns")) {
                // is namespace attribute
                nsDeclarations.put("", attribute.getValue());
            } else if (attribute.getKey().startsWith("xmlns:")) {
                nsDeclarations.put(attribute.getKey().substring(6), attribute.getValue());
            }
        }
        nsResolver.push(nsDeclarations);

        // find all non-namespace attributes
        List<Attribute> nonNsAttributes = new ArrayList<Attribute>();
        for (Entry<String, String> attribute : attributes.entrySet()) {
            String attQname = attribute.getKey();

            // only report NS declaration attributes if the feature is set to
            if (reportNsAttributes) {
                nonNsAttributes.add(new Attribute(attQname, null, attQname, attribute.getValue()));
            } else if (!attQname.equals("xmlns") && !attQname.startsWith("xmlns:")) {
                String attLocalName = extractLocalName(attQname);
                String attPrefix = extractNsPrefix(attQname);
                String attUri;
                if (attPrefix.length() > 0) {
                    attUri = nsResolver.resolveUri(attPrefix);
                    if (attUri == null) {
                        if (attPrefix.length() > 0) {
                            fatalError("Undeclared namespace prefix: " + attPrefix);
                            return;
                        } else {
                            attUri = "";
                        }
                    }
                } else {
                    // by default, attributes are in the empty namespace
                    attUri = "";
                }
                nonNsAttributes.add(new Attribute(attLocalName, attUri, attQname, attribute.getValue()));
            }
        }

        String prefix = extractNsPrefix(qname);
        String uri = nsResolver.resolveUri(prefix);
        if (uri == null) {
            if (prefix.length() > 0) {
                fatalError("Undeclared namespace prefix: " + prefix);
                return;
            } else {
                uri = "";
            }
        }

        String localName = extractLocalName(qname);

        elements.add(fullyQualifiedName(uri, qname));

        contentHandler.startElement(uri, localName, qname, new DefaultAttributes(nonNsAttributes));
    }