List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
public static String getNodeText(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList childNodes = node.getChildNodes(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) { Node myNode = childNodes.item(i); buffer.append(myNode.getNodeValue()); }//from w w w .java2s. c o m } return buffer.toString(); } return ""; }
From source file:Main.java
public static String getTextContent(Node node) { Node n = node.getFirstChild(); if (n == null) return ""; String s = n.getNodeValue(); if (s == null) s = "";/*from w w w. j av a 2 s . co m*/ return s; }
From source file:Main.java
public static void printNodeIterator(NodeIterator iterator) { Node n; while ((n = iterator.nextNode()) != null) { System.out.println("Node:" + n.getNodeValue()); }// ww w . ja va 2 s.co m }
From source file:Main.java
public static Object getBean(String className) { try {//from ww w . java 2s . co 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
/** * Returns the attribute value with the given id for the Node * //from w w w .jav a2 s .c om * @param n * @param id * @return */ public static String getAttribute(Node n, String id) { String result = null; NamedNodeMap attrMap = n.getAttributes(); if (null != attrMap) { Node attr = attrMap.getNamedItem(id); result = (attr == null) ? null : attr.getNodeValue(); } if (null != result) { result = result.trim(); } return result; }
From source file:Main.java
public static Object getBean() { try {//from w w w. j a va 2s .c om DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document document; document = builder.parse(new File("config.xml")); NodeList nl = document.getElementsByTagName("StrategyClassName"); Node classNode = nl.item(0).getFirstChild(); String cName = classNode.getNodeValue(); System.out.println(cName); Class c = Class.forName("com.seven.strategy.sort." + cName); Object object = c.newInstance(); return object; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Util.java
/** * Renvoie le texte contenu dans un lment * /* ww w .j a v a2 s. c o m*/ * @param node * @return */ public static String getText(final Node node) { Node text = node.getFirstChild(); if (text == null) return ""; return text.getNodeValue(); }
From source file:Main.java
public static String getTextValue(final Element element, final String tagName) { Node n = getNode(element, tagName); if (n != null) { Node child = n.getFirstChild(); return (child == null) ? "" : child.getNodeValue(); }//from w w w.ja v a 2 s . c o m return null; }
From source file:Main.java
public static boolean getBooleanValue(NamedNodeMap values, String name, boolean defaultValue) { Node node = values.getNamedItem(name); return node == null ? defaultValue : Boolean.valueOf(node.getNodeValue()).booleanValue(); }
From source file:Main.java
public static void dump(Node node) { System.out.println("Node: " + node.getNodeName()); NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { for (int i = 0; i < nnm.getLength(); i++) { Node n = nnm.item(i); System.out.println(" " + n.getNodeName() + ":" + n.getNodeValue()); }//from ww w . j a v a2 s .c o m } }