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
static public Node getNode(String tagName, NodeList nodes) { for (int x = 0; x < nodes.getLength(); x++) { Node node = nodes.item(x); if (node.getNodeName().equalsIgnoreCase(tagName)) { return node; }// w ww . j a va 2s . c om } return null; }
From source file:Main.java
@Nullable public static Node getNode(String tagName, NodeList nodes) { for (int x = 0; x < nodes.getLength(); x++) { Node node = nodes.item(x); if (node.getNodeName().equalsIgnoreCase(tagName)) { return node; }/* w w w . java 2 s . c o m*/ } return null; }
From source file:Main.java
public 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 Object getBean(String className) { try {//from w w w . j a va 2s. c o m DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc = builder.parse(new File(configPath)); NodeList nl = doc.getElementsByTagName(className); Node classNode = nl.item(0).getFirstChild(); String chartType = classNode.getNodeValue().trim(); Class c = Class.forName(chartType); return c.newInstance(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
@SuppressWarnings("finally") public static String getType(String relativePath, String nodeName) { try {// w ww . ja v a 2 s . c o m DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc; doc = builder.parse(new File(path + relativePath)); NodeList nl = doc.getElementsByTagName(nodeName); Node classNode = nl.item(0).getFirstChild(); nodeString = classNode.getNodeValue().trim(); } catch (Exception e) { e.printStackTrace(); } finally { return nodeString; } }
From source file:Main.java
public static Object getClassFromXML() throws Exception { //create DOM object DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(new File("property.xml")); //get the node name and get the class name NodeList nodeList = document.getElementsByTagName("className"); Node node = nodeList.item(0).getFirstChild(); String className = node.getNodeValue(); //return an object through the class name Class tempClass = Class.forName(className); Object object = tempClass.newInstance(); return object; }
From source file:Main.java
public static Node getNode(Document doc, String tagName) { NodeList scriptNodes = doc.getElementsByTagName(tagName); return scriptNodes.item(0); }
From source file:Main.java
public static void getEntityValues(Node node, Map map) { if (node instanceof EntityReference) { map.put(node.getNodeName(), node); }//from ww w. j a va 2 s. c om NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { getEntityValues(list.item(i), map); } }
From source file:Main.java
public static Element getRoot(Document document, String root) { if (document == null) throw new IllegalArgumentException("Null document"); NodeList nodeList = document.getElementsByTagName(root); return nodeList.item(0) != null ? (Element) nodeList.item(0) : null; }
From source file:Main.java
public static Element getElementNS(Element el, String nameSpaceURI, String tagName, int index) { NodeList list = el.getElementsByTagNameNS(nameSpaceURI, tagName); return (Element) list.item(index); }