Search in sources :

Example 1 with NamedNodeMapImpl

use of org.exist.dom.NamedNodeMapImpl in project exist by eXist-db.

the class ElementImpl method getAttributes.

@Override
public NamedNodeMap getAttributes() {
    final NamedNodeMapImpl map = new NamedNodeMapImpl(document, true);
    int attr = document.alpha[nodeNumber];
    if (-1 < attr) {
        while (attr < document.nextAttr && document.attrParent[attr] == nodeNumber) {
            map.setNamedItem(new AttrImpl(document, attr));
            ++attr;
        }
    }
    // add namespace declarations attached to this element
    int ns = document.alphaLen[nodeNumber];
    if (ns < 0) {
        return (map);
    }
    while (ns < document.nextNamespace && document.namespaceParent[ns] == nodeNumber) {
        final NamespaceNode node = new NamespaceNode(document, ns);
        map.setNamedItem(node);
        ++ns;
    }
    return map;
}
Also used : NamedNodeMapImpl(org.exist.dom.NamedNodeMapImpl)

Example 2 with NamedNodeMapImpl

use of org.exist.dom.NamedNodeMapImpl in project exist by eXist-db.

the class ElementImpl method getAttributes.

@Override
public NamedNodeMap getAttributes() {
    final org.exist.dom.NamedNodeMapImpl map = new NamedNodeMapImpl(ownerDocument, true);
    if (hasAttributes()) {
        try (final DBBroker broker = ownerDocument.getBrokerPool().getBroker();
            final INodeIterator iterator = broker.getNodeIterator(this)) {
            // skip self
            iterator.next();
            final int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                final IStoredNode next = iterator.next();
                if (next.getNodeType() != Node.ATTRIBUTE_NODE) {
                    break;
                }
                map.setNamedItem(next);
            }
        } catch (final EXistException | IOException e) {
            LOG.warn("Exception while retrieving attributes: {}", e.getMessage());
        }
    }
    if (declaresNamespacePrefixes()) {
        for (final Map.Entry<String, String> entry : namespaceMappings.entrySet()) {
            final String prefix = entry.getKey();
            final String ns = entry.getValue();
            final QName attrName = new QName(prefix, Namespaces.XMLNS_NS, XMLConstants.XMLNS_ATTRIBUTE);
            final AttrImpl attr = new AttrImpl(attrName, ns, null);
            attr.setOwnerDocument(ownerDocument);
            map.setNamedItem(attr);
        }
    }
    return map;
}
Also used : org.w3c.dom(org.w3c.dom) NamedNodeMapImpl(org.exist.dom.NamedNodeMapImpl) QName(org.exist.dom.QName) EXistException(org.exist.EXistException) IOException(java.io.IOException) NamedNodeMapImpl(org.exist.dom.NamedNodeMapImpl) INodeIterator(org.exist.storage.dom.INodeIterator)

Aggregations

NamedNodeMapImpl (org.exist.dom.NamedNodeMapImpl)2 IOException (java.io.IOException)1 EXistException (org.exist.EXistException)1 QName (org.exist.dom.QName)1 INodeIterator (org.exist.storage.dom.INodeIterator)1 org.w3c.dom (org.w3c.dom)1