List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
public static List<String> parseXmlFile(String nodeName, Document file) { List<String> nodeTexts = new ArrayList<String>(); NodeList nodes = file.getElementsByTagName(nodeName); for (int index = 0; index < nodes.getLength(); ++index) { Node node = nodes.item(index).getFirstChild(); String nodeText = node.getNodeValue(); nodeTexts.add(nodeText);/*from www. j a v a 2s. c o m*/ } return nodeTexts; }
From source file:Main.java
public static Properties extractProperties(Node node) { Properties props = new Properties(); NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); props.put(item.getNodeName(), item.getNodeValue()); }// w w w.j a va 2 s . com } return props; }
From source file:Main.java
public static Object getBean() { try {/*from ww w . j a v a 2 s . c om*/ DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc = builder.parse(new File("src/config.xml")); NodeList nl = doc.getElementsByTagName("className"); Node node = nl.item(0).getFirstChild(); String cName = node.getNodeValue(); Class clazz = Class.forName(cName); Object obj = clazz.newInstance(); return obj; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getTagValue(Element root, String tagName) { String returnString = ""; NodeList list = root.getElementsByTagName(tagName); for (int loop = 0; loop < list.getLength(); loop++) { Node node = list.item(loop); if (node != null) { Node child = node.getFirstChild(); if ((child != null) && (child.getNodeValue() != null)) { return child.getNodeValue(); }//from ww w . ja v a2 s .co m } } return returnString; }
From source file:Main.java
/** * Gets an element value/*from ww w.j a v a 2 s .c o m*/ * * @param valueTag * @param fromElement * @return */ public static String getTagValue(String valueTag, Element fromElement) { NodeList nodeList = fromElement.getElementsByTagName(valueTag); if (nodeList != null && nodeList.getLength() > 0) { NodeList childList = nodeList.item(0).getChildNodes(); if (childList != null && childList.getLength() > 0) { Node node = (Node) childList.item(0); return node.getNodeValue(); } } return null; }
From source file:Main.java
/** * Gets the attribute value as string.//from w w w . j a va 2s. c o m * *@param node the node from which to get the attribute value *@return The attribute value as a string *@exception DOMException if an error occurs while getting the attrubute * value */ public final static String getAttributeValueAsString(Node node) throws DOMException { if (node != null) { return node.getNodeValue(); } return null; }
From source file:Main.java
private static void addAttrDirect(Map<String, Object> values, Element el) { NamedNodeMap attrs = el.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); values.put(attr.getNodeName(), attr.getNodeValue()); }//from w w w. j a va 2s . co m }
From source file:Main.java
public static String getField(NamedNodeMap fields, String fieldName) { Node field = fields.getNamedItem(fieldName); if (field != null) return field.getNodeValue(); else/*from ww w.ja v a 2 s. c o m*/ return new String(); }
From source file:Main.java
public static HashMap<String, String> getNodeAttributesMap(Node node) { HashMap<String, String> map = new HashMap<String, String>(); NamedNodeMap namedNodeMap = node.getAttributes(); for (int i = 0; i < namedNodeMap.getLength(); i++) { Node attribute = namedNodeMap.item(i); map.put(attribute.getNodeName(), attribute.getNodeValue()); }//from w w w . ja va2s. c o m return map; }
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; }