Java Utililty Methods XML Attribute Load

List of utility methods to do XML Attribute Load

Description

The list of methods to do XML Attribute Load are organized into topic(s).

Method

HashMapgetAllAttributes(Element e)
get All Attributes
HashMap<String, String> m = new HashMap<>();
NamedNodeMap nnm = e.getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
    m.put(nnm.item(i).getNodeName(), nnm.item(i).getNodeValue());
return m;
MapgetAllAttributes(Element elem, String name)
Get the attribute values of a given name/value pair for the first XML org.w3c.dom.Element of given name.
Map<String, String> attributes = new TreeMap<String, String>();
NodeList nodeList = elem.getElementsByTagName(name);
int length = nodeList.getLength();
for (int n = 0; n < length; ++n) {
    attributes.put(((Element) nodeList.item(n)).getAttribute("name"),
            ((Element) nodeList.item(n)).getAttribute("value"));
return attributes;
...
ArrayListgetAllAttributes(Element element)
Get all attributes of the specified element
final NamedNodeMap nodeMap = element.getAttributes();
final ArrayList<Attr> result = new ArrayList<Attr>();
for (int i = 0; i < nodeMap.getLength(); i++)
    result.add((Attr) nodeMap.item(i));
return result;
HashMapgetAllAttributes(Node node)
get All Attributes
HashMap<String, String> attributes = new HashMap<String, String>();
NamedNodeMap attr = node.getAttributes();
for (int j = 0; j < attr.getLength(); j++) {
    attributes.put(attr.item(j).getNodeName(), attr.item(j).getNodeValue());
return attributes;
MapgetAllAttributes(Node node)
Returns a map of all node's attributes.
HashMap<String, String> attrs = new HashMap<String, String>();
NamedNodeMap nmm = node.getAttributes();
for (int j = 0; j < nmm.getLength(); j++) {
    Node attribute = nmm.item(j);
    if (attribute.getNodeType() != Node.ATTRIBUTE_NODE) {
        continue;
    attrs.put(attribute.getNodeName(), attribute.getNodeValue());
...
MapgetAllAttributesAsMap(@Nullable final Element aSrcNode)
get All Attributes As Map
if (aSrcNode != null) {
    final NamedNodeMap aNNM = aSrcNode.getAttributes();
    if (aNNM != null) {
        final Map<String, String> aMap = new LinkedHashMap<String, String>(aNNM.getLength());
        final int nMax = aNNM.getLength();
        for (int i = 0; i < nMax; ++i) {
            final Attr aAttr = (Attr) aNNM.item(i);
            aMap.put(aAttr.getName(), aAttr.getValue());
...
voidgetAllAttrs(Element parent, String name, List lst)
get All Attrs
for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        getAllAttrValueByName(child, name);
        List<String> tmp = getAllAttrValueByName(child, name);
        if (tmp != null) {
            lst.addAll(tmp);
        } else {
            getAllAttrs((Element) child, name, lst);
...
ListgetAllAttrValueByName(Node item, String name)
get All Attr Value By Name
List<String> lst = null;
NamedNodeMap attributes = item.getAttributes();
int numAttrs = attributes.getLength();
for (int i = 0; i < numAttrs; i++) {
    Attr attr = (Attr) attributes.item(i);
    String attrName = attr.getNodeName();
    if (name.equals(attrName)) {
        if (lst == null) {
...
StringgetAllElementAttributes(Element element)
get All Element Attributes
return getElementAttributes(element, new ArrayList<String>());
ListgetAllElementsWithAttrId(final Element element, final String namespace)
get All Elements With Attr Id
List<Element> list = new LinkedList<Element>();
if (elementHasId(element, namespace)) {
    list.add(element);
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node child = children.item(i);
    if (child instanceof Element == false) {
...