Here you can find the source of getAttributeValue(Element e, String name)
Parameter | Description |
---|---|
e | a parameter |
name | a parameter |
static public String getAttributeValue(Element e, String name)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006 Vladimir Silva and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from www .j ava 2 s.c o m * Vladimir Silva - initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Get an attribute value * @param e * @param name * @return */ static public String getAttributeValue(Element e, String name) { Node n = e.getAttributes().getNamedItem(name); return (n != null) ? n.getNodeValue() : null; } /** * Extract the value of a XML element * @param e Document element * @param name * @return */ static public String getNodeValue(Element e, String name) { NodeList nl = e.getElementsByTagName(name); try { return (nl != null && nl.getLength() > 0) ? nl.item(0).getFirstChild().getNodeValue().trim() : null; } catch (NullPointerException ex) { return null; } } }