Here you can find the source of getAttributes(Node element)
Parameter | Description |
---|---|
element | The element whose attributes need to be fetched |
public static Map<Object, Object> getAttributes(Node element)
//package com.java2s; /*//from w w w .j a v a2s . co m * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ import java.util.HashMap; import java.util.Map; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Fetches the attributes associated with the given node * * @param element The element whose attributes need to be fetched * @return A map containing all the attributes */ public static Map<Object, Object> getAttributes(Node element) { Map<Object, Object> attr = new HashMap<Object, Object>(); attr.clear(); NamedNodeMap attributes = element.getAttributes(); if (attributes != null) { // has attributes for (int i = 0; i < attributes.getLength(); i++) { Node n = attributes.item(i); attr.put(n.getNodeName(), n.getNodeValue()); } } return attr; } }