Here you can find the source of printAttribute(String nombre, NodeList nodes)
Parameter | Description |
---|---|
nodo | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static List printAttribute(String nombre, NodeList nodes) throws Exception
//package com.java2s; /**// w w w . ja va 2s .c o m * TNTConcept Easy Enterprise Management by Autentia Real Bussiness Solution S.L. * Copyright (C) 2007 Autentia Real Bussiness Solution S.L. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; import java.util.List; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Este metodo convierte un objeto de tipo org.w3c.dom.NodeList a List * Este metodo solo saca el atributo especificado con nombre * @param nodo * @return * @throws Exception */ public static List printAttribute(String nombre, NodeList nodes) throws Exception { List<String> nodeText = new ArrayList<String>(); for (int i = 0; i < nodes.getLength(); i++) { Node node = (Node) nodes.item(i); nodeText.add(normalizeName(giveAttributeNode(nombre, node))); } return nodeText; } /** * Este metodo normaliza un texto pasado por parametro * @param nombre * @return */ public static String normalizeName(String name) { return name.replace('.', ' '); } /** * Devuelve el valor del atributo "nombre" de un nodo * @param nombre * @param nodo * @return */ public static String giveAttributeNode(String name, Node node) { NamedNodeMap map = node.getAttributes(); String value = null; if (map != null) { Node nodoAt = map.getNamedItem(name); if (nodoAt != null) value = nodoAt.getNodeValue(); } return value; } }