Java XML Attribute Get getAttributes(Element root, String elementName, String[] wantedAttributes)

Here you can find the source of getAttributes(Element root, String elementName, String[] wantedAttributes)

Description

get Attributes

License

GNU General Public License

Declaration

public static String[][] getAttributes(Element root,
        String elementName, String[] wantedAttributes) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 * Version: GPL 2.0//from  ww w . j  a  v  a  2s. c o m
 *
 * The contents of this file are subject to the GNU General Public
 * License Version 2 or later (the "GPL").
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *   MiniG.org project members
 *
 * ***** END LICENSE BLOCK ***** */

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {

    public static String[][] getAttributes(Element root,
            String elementName, String[] wantedAttributes) {
        NodeList list = root.getElementsByTagName(elementName);
        String[][] ret = new String[list.getLength()][wantedAttributes.length];
        for (int i = 0; i < list.getLength(); i++) {
            Element elem = (Element) list.item(i);
            for (int j = 0; j < wantedAttributes.length; j++) {
                ret[i][j] = elem.getAttribute(wantedAttributes[j]);
            }
        }
        return ret;
    }
}

Related

  1. getAttributes(Element el)
  2. getAttributes(Element el)
  3. getAttributes(Element el)
  4. getAttributes(Element element)
  5. getAttributes(Element element)
  6. getAttributes(final Element el)
  7. getAttributes(final Element element)
  8. getAttributes(final Node node, final String[] attributeNames)
  9. getAttributes(Node element)