List of usage examples for org.w3c.dom NodeList item
public Node item(int index);
index
th item in the collection. From source file:Main.java
private static String getTagValue(String sTag, Element eElement) { NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); Node nValue = (Node) nlList.item(0); return nValue.getNodeValue(); }
From source file:Main.java
public static void visit(Node node, int level) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node childNode = list.item(i); visit(childNode, level + 1);//from w ww . j a va2s . c o m } }
From source file:Main.java
static public Element getElementByTagName(Element element, String name, int index) { NodeList list = element.getElementsByTagName(name); return (Element) list.item(index); }
From source file:Main.java
/** * Get the text for an element, which is considered the first Text child element. * @param element/*from ww w . j av a 2 s . c o m*/ * @returns the text or <code>null</code> */ public static String getText(Element element) { NodeList nodeList = element.getChildNodes(); if (nodeList.item(0) instanceof Text) { return nodeList.item(0).getTextContent(); } return null; }
From source file:Main.java
public static void visit(Node node, int level) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node childNode = list.item(i); System.out.println(childNode); visit(childNode, level + 1);//from w w w . j a va2s. c om } }
From source file:Main.java
public static Element getElement(Document doc, String tagName, int index) { //Given an XML document and a tag return an Element at a given index NodeList rows = doc.getDocumentElement().getElementsByTagName(tagName); return (Element) rows.item(index); }
From source file:Main.java
public static Element getChildren(Element element, String childName) { NodeList ndLs = element.getElementsByTagName(childName); return (Element) ndLs.item(0); }
From source file:Main.java
/** * Tranform a node list into a document fragment *//*from w w w . ja v a 2 s . c om*/ public static Node toDocumentFragment(NodeList list) { if (list.getLength() == 1 && list.item(0) instanceof Document) return list.item(0); Document document = newDocument(); DocumentFragment fragment = document.createDocumentFragment(); for (int i = 0; i < list.getLength(); i++) fragment.appendChild(document.adoptNode(list.item(i).cloneNode(true))); return fragment; }
From source file:Main.java
public static String getBrandName() { try {/* ww w. j a v a 2 s . com*/ DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc = builder.parse(new File("configTV.xml")); NodeList nl = doc.getElementsByTagName("Name"); Node classNode = nl.item(0).getFirstChild(); String Name = classNode.getNodeValue().trim(); return Name; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
/** * Gets the first text value of a NodeList * @param nList NodeList// w w w . ja va 2 s . c o m * @return first text value of a NodeList */ public static String getFirstTextValueFromNodeList(NodeList nList) { if (nList != null && nList.getLength() != 0) { return nList.item(0).getTextContent(); } return null; }