Java XML Attribute Print printAttribute(String nombre, NodeList nodes)

Here you can find the source of printAttribute(String nombre, NodeList nodes)

Description

print Attribute

License

Open Source License

Declaration

public static List printAttribute(String nombre, NodeList nodes) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.List;

public class Main {

    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)));
        }//www .  j  a  v  a  2  s  . co m
        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;
    }
}

Related

  1. printAttribute(Node node, int level)
  2. printAttribute(String nombre, NodeList nodes)
  3. printAttribute(XMLStreamReader xmlr, int index, StringBuffer result)
  4. printAttributes(Element element)
  5. printAttributes(NamedNodeMap attributes, String indent, boolean descend)
  6. printAttributes(XMLStreamReader xmlr)