Example usage for org.jdom2 Element getAttributes

List of usage examples for org.jdom2 Element getAttributes

Introduction

In this page you can find the example usage for org.jdom2 Element getAttributes.

Prototype

public List<Attribute> getAttributes() 

Source Link

Document

This returns the complete set of attributes for this element, as a List of Attribute objects in no particular order, or an empty list if there are none.

Usage

From source file:se.miun.itm.input.model.param.Param.java

License:Open Source License

private void initFromOriginal(Element original) {
    // init attributes
    setNamespace(original.getNamespace());
    setName(original.getName());//from   w  w w. j a v a2s  .  c o  m
    Attribute attr;
    for (Object content : original.getAttributes()) {
        attr = (Attribute) content;
        setAttribute(attr.getName(), attr.getValue());
    }

    // move children
    Element childE;
    Object[] children = original.getChildren().toArray();
    for (Object child : children) {
        childE = (Element) child;
        original.removeContent(childE);
        addContent(childE);
    }

    // attach to parent
    Element parent = original.getParentElement();
    parent.removeContent(original);
    parent.addContent(this);
}

From source file:site.util.EvXmlUtil.java

License:BSD License

/**
 * Checks if name and attributes equal, not content
 *///from   www  .ja va  2s.  c o m
public static boolean elementsEqual(Element a, Element b) {
    if (a.getName().equals(b.getName())) {
        for (Object o : a.getAttributes()) {
            Attribute attra = (Attribute) o;
            Attribute attrb = b.getAttribute(attra.getName());
            if (attrb == null)
                return false;
            if (!attra.getValue().equals(attrb.getValue()))
                return false;
        }
        for (Object o : b.getAttributes()) {
            Attribute attrb = (Attribute) o;
            Attribute attra = a.getAttribute(attrb.getName());
            if (attra == null)
                return false;
            if (!attrb.getValue().equals(attra.getValue()))
                return false;
        }
        return true;
    } else
        return false;
}

From source file:xml.JDOMConverter.java

License:Apache License

/**.
 * Filters the object to convert it// ww w  . jav  a2 s.com
 * @param o : Object
 * @thows JSONException
 * @see JSONConverter#tree
 * @see JSONConverter#readJsonStream(InputStream)
 */
public final void filter(final Object o) throws JSONException {
    if (o instanceof Element) {
        Element element = (Element) o;
        String elemName = element.getName();
        List children = element.getContent();
        List attribute = element.getAttributes();
        Iterator ita = attribute.iterator();
        Iterator itc = children.iterator();

        current++;
        tree.add(current, new JSONObject());

        // Attributes
        while (ita.hasNext()) {
            Object child = ita.next();
            filter(child);
        }
        // Children
        while (itc.hasNext()) {
            Object child = itc.next();
            filter(child);
        }
        handleArray(elemName);
        tree.remove(current);
        current--;
    } else if (o instanceof Attribute) {
        handleAttribute((Attribute) o);
    } else if (o instanceof Text) {
        handleText((Text) o);
    }
}