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 Node getNode(NodeList nl, int idx) {
    Node n = nl.item(idx);
    n.getParentNode().removeChild(n);//for performance
    return n;/*ww  w  .ja  v  a  2s .  c o  m*/
}

From source file:Main.java

public static String getOnlyIdOfXmiAttribute(NodeList elements, int i) {
    Node href = elements.item(i).getAttributes().getNamedItem("href");
    if (href != null) {
        String currentValue = href.getNodeValue();
        return currentValue.substring(currentValue.indexOf("#") + 1, currentValue.length());
    } else {//from   www  .ja v  a  2  s  . c om
        return null;
    }
}

From source file:Main.java

public static final String getData(Node node) {
    Element e = (Element) node;
    NodeList childNodes = e.getChildNodes();
    Text text = (Text) childNodes.item(0);
    return (text != null) ? text.getData() : "";
}

From source file:Main.java

public static String getAttribute(NodeList nodeList, String attName) {
    Element elm = (Element) nodeList.item(0);
    return elm.getAttribute(attName);
}

From source file:Main.java

public static String getNodeText(Node node) {
    NodeList fstNm = node.getChildNodes();
    String ret = fstNm.item(0).getNodeValue();
    return ret;//ww w  . ja  v  a  2 s  . co  m
}

From source file:Main.java

static private Element getFirstElement(NodeList list) {
    return list.getLength() > 0 ? (Element) list.item(0) : null;
}

From source file:Main.java

public static void edit(Document doc) {
    NodeList list = doc.getElementsByTagName("name");
    Element element = (Element) list.item(0);

    Element dup = (Element) element.cloneNode(true);

    element.getParentNode().insertBefore(dup, element.getNextSibling());
}

From source file:Main.java

public static String getText(NodeList elem) {
    if (elem.getLength() > 0 && elem.item(0).getFirstChild() != null)
        return elem.item(0).getFirstChild().getTextContent();
    return "";
}

From source file:Main.java

static String getValue(String tag, Element element) {
    NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
    Node node = (Node) nodes.item(0);
    return node.getNodeValue();
}

From source file:Main.java

/**
 * Get Element from Nodelist//w  ww .  j av a  2 s . c  o m
 * @param list NodeList
 * @param index Element index
 * @return w3c.dom.Element
 */
public static Element getElementFromItem(NodeList list, int index) {
    return (Element) list.item(index);
}