Java XML Attribute Load getAllElementAttributes(Element element)

Here you can find the source of getAllElementAttributes(Element element)

Description

get All Element Attributes

License

Apache License

Parameter

Parameter Description
element The DOM Element.

Return

A string representation of all the element's attributes.

Declaration

public static String getAllElementAttributes(Element element) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Attr;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

public class Main {
    /**//from  w w w. j a v  a 2 s. com
     * @param element
     *            The DOM Element.
     * @return A string representation of all the element's attributes.
     */
    public static String getAllElementAttributes(Element element) {
        return getElementAttributes(element, new ArrayList<String>());
    }

    /**
     * @param element
     *            The DOM Element.
     * @param exclude
     *            the list of exclude strings.
     * @return A string representation of the element's attributes excluding exclude.
     */
    public static String getElementAttributes(Element element,
            List<String> exclude) {
        StringBuffer buffer = new StringBuffer();

        if (element != null) {
            NamedNodeMap attributes = element.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr) attributes.item(i);
                    if (!exclude.contains(attr.getNodeName())) {
                        buffer.append(attr.getNodeName() + "=");
                        buffer.append(attr.getNodeValue() + " ");
                    }
                }
            }
        }

        return buffer.toString().trim();
    }
}

Related

  1. getAllAttributes(Node node)
  2. getAllAttributes(Node node)
  3. getAllAttributesAsMap(@Nullable final Element aSrcNode)
  4. getAllAttrs(Element parent, String name, List lst)
  5. getAllAttrValueByName(Node item, String name)
  6. getAllElementsWithAttrId(final Element element, final String namespace)
  7. loadAttributes(Element e)