Example usage for org.w3c.dom NodeList item

List of usage examples for org.w3c.dom NodeList item

Introduction

In this page you can find the example usage for org.w3c.dom NodeList item.

Prototype

public Node item(int index);

Source Link

Document

Returns the indexth item in the collection.

Usage

From source file:Main.java

public static Element getElement(Document doc, String tagName, int index) {
    NodeList rows = doc.getDocumentElement().getElementsByTagName(tagName);
    return (Element) rows.item(index);
}

From source file:Main.java

public static String getSubNodeValue(Element element, String name) {
    NodeList nodeList = element.getElementsByTagName(name);
    return getNodeValue(nodeList.item(0)).trim();
}

From source file:Main.java

public static int findFirstChildIndex(Element elem, String tagName) {
    NodeList nl = elem.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i) {
        if (nl.item(i).getNodeName().equals(tagName))
            return i;
    }//from   w  w  w . j  a v  a2  s .c o m
    return -1;
}

From source file:Main.java

/**
 * Method to remove all children of g:options - element
 * /*from   w ww  . j a v a  2s .  c  o  m*/
 * @param doc document with children  g:options
 * @return document without children g:options
 */
public static Document removeAllOptions(Document doc) {
    NodeList nodes = doc.getElementsByTagName("g:options");
    Node node = nodes.item(0);
    while (node.hasChildNodes())
        node.removeChild(node.getFirstChild());
    return doc;
}

From source file:Main.java

public static Node getFirstChildNodeNamed(Node node, String name) {
    NodeList nodes = node.getChildNodes();
    for (int x = 0; x < nodes.getLength(); x++) {
        if (nodes.item(x).getNodeName().equalsIgnoreCase(name) == true) {
            return nodes.item(x);
        }//from w  w  w .ja  v a 2  s.  c o m
    }
    return null;
}

From source file:Main.java

public static String getFirstElementAttr(Element parent, String tag, String attr) {
    NodeList nl = parent.getElementsByTagName(tag);
    if (nl.getLength() > 0) {
        return ((Element) nl.item(0)).getAttribute(attr);
    }/*from   ww w. j  a v  a  2 s.co m*/
    return null;
}

From source file:Main.java

/**
 * //from  w w  w  .  ja v  a 2  s . c  om
 * @param nodeList
 * @return zda obsahuje elementy
 */
public static boolean containsElements(NodeList nodeList) {
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String getCharacterDataFromElementWithKey(final Element element, final String key) {
    String result = null;//from  w w  w  .j  a v a 2 s. com
    if (element != null) {
        final NodeList jobNodeList = element.getElementsByTagName(key);

        final Node node = jobNodeList.item(0);
        if (node != null) {
            final CharacterData characterData = (CharacterData) jobNodeList.item(0).getChildNodes().item(0);
            if (characterData != null) {
                result = characterData.getNodeValue();
            }
        }
    }
    return result;
}

From source file:Main.java

public static String getTag(org.w3c.dom.Element e, String index) {
    NodeList nList = e.getElementsByTagName(index);
    if (nList.getLength() != 0) {
        Node nNode = nList.item(0);
        return nNode.getTextContent();
    }//  www.  j  av  a 2 s  .c om
    return null;
}

From source file:Main.java

public static Element getFirstElement(Element element) {
    Element result = null;/*from  w  w  w .  j  a va2 s.  co m*/
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        if (nl.item(i) instanceof Element) {
            result = (Element) nl.item(i);
        }
    }
    return result;
}