2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright ©2012-2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.commons.data.xml;
12 import java.util.ArrayList;
13 import java.util.List;
15 import org.w3c.dom.Element;
16 import org.w3c.dom.NamedNodeMap;
17 import org.w3c.dom.Node;
19 public class XmlElement {
23 public XmlElement(final Element element) {
24 this.element = element;
27 public List<String> getAttributeNames() {
28 final ArrayList<String> result = new ArrayList<String>();
30 final NamedNodeMap attributes = element.getAttributes();
32 for (int i = 0; i < attributes.getLength(); i++) {
33 final Node node = attributes.item(i);
35 result.add(node.getNodeName());
41 public String getAttributeValue(final String attributeName) {
42 return element.getAttribute(attributeName);
46 public String toString() {
47 final StringBuffer result = new StringBuffer();
49 result.append("node name: " + element.getNodeName() + "\n");
51 final NamedNodeMap attributes = element.getAttributes();
53 for (int i = 0; i < attributes.getLength(); i++) {
54 final Node node = attributes.item(i);
56 result.append(" " + node.getNodeName() + "\n");
59 return result.toString();