Example usage for org.w3c.dom Node hasAttributes

List of usage examples for org.w3c.dom Node hasAttributes

Introduction

In this page you can find the example usage for org.w3c.dom Node hasAttributes.

Prototype

public boolean hasAttributes();

Source Link

Document

Returns whether this node (if it is an element) has any attributes.

Usage

From source file:us.conxio.XMLUtilities.AttributeMap.java

/**
 * A static org.w3c.dom.Node extraction constructor.
 * @param node The node from which to construct the returned AttributeMap.
 * @param allowed A String array of allowed attribute names.
 * @return The resulting AttributeMap, or null, if the operation fails.
 *///from  w w w .  j  a  va2  s.  c o m
public static AttributeMap getAttributes(Node node, String[] allowed) {
    if (node == null)
        return null;
    if (!node.hasAttributes())
        return null;

    AttributeMap newMap = new AttributeMap();

    NamedNodeMap attribs = node.getAttributes();
    int attribCount = attribs.getLength();
    for (int index = 0; index < attribCount; ++index) {
        Node attribNode = attribs.item(index);
        String attribName = attribNode.getNodeName().toLowerCase();
        if (XMLUtils.equalsAny(attribName, allowed)) {
            newMap._add(attribName, attribNode.getNodeValue());
        } // if
    } // for

    if (newMap.entryCount() > 0)
        return newMap;

    return null;
}

From source file:us.conxio.XMLUtilities.AttributeMap.java

/**
 * A static org.w3c.dom.Node extraction constructor.
 * @param node The node from which to construct the returned AttributeMap
 * @return The resulting AttributeMap, or null, if the operation fails.
 *//*from w  ww  .  j  a v a2s.c o m*/
public static AttributeMap getAttributes(Node node) {
    if (node == null)
        return null;
    if (!node.hasAttributes())
        return null;

    AttributeMap newMap = new AttributeMap(node);
    if (newMap.entryCount() > 0)
        return newMap;

    return null;
}