List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
public static Object getBean() { try {// w ww . jav a2 s . c o m DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document document; document = builder.parse(new File("config.xml")); NodeList nl = document.getElementsByTagName("TemplateClassName"); Node classNode = nl.item(0).getFirstChild(); String cName = classNode.getNodeValue(); System.out.println(cName); Class c = Class.forName("com.seven.templatemethod.one." + cName); Object object = c.newInstance(); return object; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static void traverseAttributes(JsonObject childJson, Node childNode) { NamedNodeMap attrNodeMap = childNode.getAttributes(); for (int j = 0; j < attrNodeMap.getLength(); j++) { Node attrNode = attrNodeMap.item(j); childJson.addProperty("-" + attrNode.getNodeName(), attrNode.getNodeValue()); }/*from w w w . ja va 2 s .c o m*/ }
From source file:Main.java
public static void setNodeValue(Node node, String name, String value) { String s = node.getNodeValue(); if (s != null) { node.setNodeValue(value);//from w ww .j a v a 2s .c o m return; } NodeList nodelist = node.getChildNodes(); for (int i = 0; i < nodelist.getLength(); i++) { if (nodelist.item(i) instanceof Text) { Text text = (Text) nodelist.item(i); text.setData(value); return; } } return; }
From source file:Main.java
private static String getSubTagValue(Node node, String subTagName) { String returnString = ""; if (node != null) { NodeList children = node.getChildNodes(); for (int innerLoop = 0; innerLoop < children.getLength(); innerLoop++) { Node child = children.item(innerLoop); if ((child != null) && (child.getNodeName() != null) && child.getNodeName().equals(subTagName)) { Node grandChild = child.getFirstChild(); if (grandChild.getNodeValue() != null) return grandChild.getNodeValue(); }/*from www .ja v a 2s . c om*/ } // end inner loop } return returnString; }
From source file:Main.java
/** * Gets a named attribute of a Node<p> * @param node The node to search/*from w ww .j av a 2s . co m*/ * @param attr The name of the attribute to get */ public synchronized static String getAttribute(Node node, String attr) { if (node == null) throw new IllegalArgumentException("Node argument cannot be null"); if (attr == null) throw new IllegalArgumentException("Node attribute argument cannot be null"); NamedNodeMap map = node.getAttributes(); if (map != null) { Node an = map.getNamedItem(attr); if (an != null) return an.getNodeValue(); } return null; }
From source file:Main.java
public static Object getBean(String relativePath, String nodeName) { try {/*from w w w .ja v a2 s. c om*/ 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(); String className = classNode.getNodeValue().trim(); Class clazz = Class.forName(className); Object obj = clazz.newInstance(); return obj; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static Map<String, Object> getAttributes(Node node) { NamedNodeMap attribs = node.getAttributes(); int attribCount = attribs.getLength(); Map<String, Object> map = new LinkedHashMap<>(attribCount); for (int j = 0; j < attribCount; j++) { Node attrib = attribs.item(j); map.put(attrib.getNodeName(), attrib.getNodeValue()); }//from w w w . j a va 2 s.c o m return map; }
From source file:Main.java
private static String getSubTagValue(Node node, String subTagName) { String returnString = ""; if (node != null) { NodeList children = node.getChildNodes(); for (int innerLoop = 0; innerLoop < children.getLength(); innerLoop++) { Node child = children.item(innerLoop); if ((child != null) && (child.getNodeName() != null) && (child.getNodeName().equals(subTagName))) { Node grandChild = child.getFirstChild(); if (grandChild.getNodeValue() != null) { return grandChild.getNodeValue(); }//from w ww.ja va 2s . c o m } } } return returnString; }
From source file:Main.java
public static String getNodeValue(Node n) { if (n == null) return null; String val = n.getNodeValue(); if (val == null) { Node child = n.getFirstChild(); if (child != null) { val = child.getNodeValue(); }/*from w w w . j a va2s . c o m*/ } return val; }
From source file:Main.java
/** * This grabs the attributes from a dom node and overwrites those values with those * specified by the overwrite map./* www . ja v a 2s. co m*/ * * @param node node for building * @param overwrite map of attributes to overwrite * @return map of attributes */ public static Map<String, String> mapifyAttrs(Node node, Map<String, String> overwrite) { Map<String, String> map = new HashMap<String, String>(); NamedNodeMap nnMap = node.getAttributes(); for (int i = 0; i < nnMap.getLength(); i++) { Node attr = nnMap.item(i); map.put(attr.getNodeName(), attr.getNodeValue()); } if (overwrite != null) { for (Map.Entry<String, String> e : overwrite.entrySet()) { map.put(e.getKey(), e.getValue()); } } return map; }