List of usage examples for org.w3c.dom Node getNodeName
public String getNodeName();
From source file:org.datacleaner.util.http.HttpXmlUtils.java
public static List<Node> getChildNodesByName(Node parentNode, String childNodeName) { List<Node> result = new ArrayList<Node>(); if (childNodeName != null) { NodeList childNodes = parentNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNodeName.equals(childNode.getNodeName())) { result.add(childNode);//from w w w . j a v a 2 s . co m } } } return result; }
From source file:com.nexmo.client.verify.endpoints.SharedParsers.java
protected static VerifyResult parseVerifyResponseXmlNode(Element root) throws NexmoResponseParseException { String requestId = null;/* w w w .ja v a2 s . co m*/ int status = -1; String errorText = null; NodeList fields = root.getChildNodes(); for (int i = 0; i < fields.getLength(); i++) { Node node = fields.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; String name = node.getNodeName(); if ("request_id".equals(name)) { requestId = XmlUtil.stringValue(node); } else if ("status".equals(name)) { String str = XmlUtil.stringValue(node); try { if (str != null) status = Integer.parseInt(str); } catch (NumberFormatException e) { log.error("xml parser .. invalid value in <status> node [ " + str + " ] "); status = BaseResult.STATUS_INTERNAL_ERROR; } } else if ("error_text".equals(name)) { errorText = XmlUtil.stringValue(node); } } if (status == -1) throw new NexmoResponseParseException("Xml Parser - did not find a <status> node"); // Is this a temporary error ? boolean temporaryError = (status == BaseResult.STATUS_THROTTLED || status == BaseResult.STATUS_INTERNAL_ERROR); return new VerifyResult(status, requestId, errorText, temporaryError); }
From source file:Main.java
/** * <p>This helper method loads the XML properties from a specific * XML element, or set of elements.</p> * * @param nodeList <code>List</code> of elements to load from. * @param baseName the base name of this property. *///w w w .j av a2s .c o m private static void loadFromElements(Map<String, String> result, NodeList nodeList, StringBuffer baseName) { // Iterate through each element for (int s = 0; s < nodeList.getLength(); s++) { Node current = nodeList.item(s); if (current.getNodeType() == Node.ELEMENT_NODE) { String name = current.getNodeName(); String text = null; NodeList childNodes = current.getChildNodes(); if (childNodes.getLength() > 0) { text = current.getChildNodes().item(0).getNodeValue(); } // String text = current.getAttributeValue("value"); // Don't add "." if no baseName if (baseName.length() > 0) { baseName.append("."); } baseName.append(name); // See if we have an element value if ((text == null) || (text.equals(""))) { // If no text, recurse on children loadFromElements(result, current.getChildNodes(), baseName); } else { // If text, this is a property result.put(baseName.toString(), text); } // On unwind from recursion, remove last name if (baseName.length() == name.length()) { baseName.setLength(0); } else { baseName.setLength(baseName.length() - (name.length() + 1)); } } } }
From source file:com.weibo.wesync.notify.xml.DomUtils.java
/** Matches the given node's name and local name against the given desired name. */ private static boolean nodeNameMatch(Node node, String desiredName) { return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName())); }
From source file:org.owasp.benchmark.tools.BenchmarkCrawler.java
/***************************** XML STUFF ****************************/ public static Node getNamedNode(String name, NodeList list) { for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeName().equals(name)) { return n; }//from w w w . j a va 2 s . c om } return null; }
From source file:org.owasp.benchmark.tools.BenchmarkCrawler.java
public static List<Node> getNamedNodes(String name, NodeList list) { List<Node> results = new ArrayList<Node>(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeName().equals(name)) { // System.out.println(">> " + n.getNodeName() + "::" + n.getNodeValue()); results.add(n);/*from ww w .j a va 2 s . c o m*/ } } return results; }
From source file:Main.java
public static void printTree(Node doc) { if (doc == null) { System.out.println("Nothing to print!!"); return;/*w w w .j av a2 s . c o m*/ } try { System.out.println(doc.getNodeName() + " " + doc.getNodeValue()); NamedNodeMap cl = doc.getAttributes(); for (int i = 0; i < cl.getLength(); i++) { Node node = cl.item(i); System.out.println("\t" + node.getNodeName() + " ->" + node.getNodeValue()); } NodeList nl = doc.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); printTree(node); } } catch (Throwable e) { System.out.println("Cannot print!! " + e.getMessage()); } }
From source file:Main.java
public static String nodeToString(org.w3c.dom.Node domNode) { if (domNode == null) { return ""; }/*ww w . j a va2 s . c o m*/ String s = typeName[domNode.getNodeType()]; String nodeName = domNode.getNodeName(); if (!nodeName.startsWith("#")) { s += ": " + nodeName; } if (domNode.getNodeValue() != null) { if (s.startsWith("ProcInstr")) s += ", "; else s += ": "; // Trim the value to get rid of NL's at the front String t = domNode.getNodeValue().trim(); int x = t.indexOf("\n"); if (x >= 0) t = t.substring(0, x); s += t; } return s; }
From source file:Main.java
/** * @return a list of all child nodes with this name *//*ww w . ja va 2 s. co m*/ public static ArrayList<Node> getChildNodes(Node node, String name) { ArrayList<Node> results = new ArrayList<Node>(); NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node temp = nodeList.item(i); if (temp.getNodeType() != Node.ELEMENT_NODE) continue; if (name.equals(temp.getLocalName()) || name.equals(temp.getNodeName())) { results.add(temp); } } return (results); }