Java XML Attribute from Element getElementAttributes(Element element, List exclude)

Here you can find the source of getElementAttributes(Element element, List exclude)

Description

get Element Attributes

License

Apache License

Parameter

Parameter Description
element The DOM Element.
exclude the list of exclude strings.

Return

A string representation of the element's attributes excluding exclude.

Declaration

public static String getElementAttributes(Element element,
        List<String> exclude) 

Method Source Code

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

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 .c  o  m
     * @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. getElementArrayString(Element root, String name, String attrib)
  2. getElementAttr(Element element, String attr)
  3. getElementAttribute(Element element, String name)
  4. getElementAttribute(Element root, String elementName, String attribute)
  5. getElementAttribute(Element root, String elemName, String att)
  6. getElementAttributeValue(Element element, String attributeName)
  7. getElementBooleanValue(Element element, String attribute)
  8. getElementBooleanValue(Element element, String attribute)
  9. getElementBooleanValue(Element element, String attribute, boolean defaultValue)