Here you can find the source of getAllAttributes(Element elem, String name)
Parameter | Description |
---|---|
elem | the parent XML Element |
name | the name of the child text Element |
public static Map<String, String> getAllAttributes(Element elem, String name)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import org.w3c.dom.Element; import org.w3c.dom.NodeList; import java.util.Map; import java.util.TreeMap; public class Main { /**/* www. java 2 s . c om*/ * Get the attribute values of a given name/value pair for * the first XML {@code org.w3c.dom.Element} of given name. * * @param elem the parent XML Element * @param name the name of the child text Element * @return attribute name and value Map of named child Element */ public static Map<String, String> getAllAttributes(Element elem, String name) { Map<String, String> attributes = new TreeMap<String, String>(); NodeList nodeList = elem.getElementsByTagName(name); int length = nodeList.getLength(); for (int n = 0; n < length; ++n) { attributes.put(((Element) nodeList.item(n)).getAttribute("name"), ((Element) nodeList.item(n)).getAttribute("value")); } return attributes; } }