List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:Main.java
/** * Allows to retrieve the UUID of the node. * @param node node to be modified.//from www . ja v a 2s . co m * @return the UUID of the node. */ public static String getNodeId(Node node) { String nodeId = null; NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { Attr a = (Attr) nnm.getNamedItemNS(CEFX_NAMESPACE, CEFXUID); if (a == null) { String name = CEFXUID; a = (Attr) nnm.getNamedItem(name); } if (a != null) { nodeId = a.getNodeValue(); } } return nodeId; }
From source file:org.owasp.benchmark.tools.BenchmarkCrawler.java
public static String getAttributeValue(String name, Node node) { if (node == null) { return null; }// w w w .j ava2s .c om NamedNodeMap nnm = node.getAttributes(); if (nnm != null) { Node attrnode = nnm.getNamedItem(name); if (attrnode != null) { String value = attrnode.getNodeValue(); if (value.equals("[random]")) { value = getToken(); } //System.out.println("El value es: " + value); return value; } } return null; }
From source file:Main.java
/** * Set or add node attribute./*from ww w.j a v a2 s . c o m*/ * * @param node * the node * @param attributeName * the attribute name * @param attributeValue * the attribute value * @param doc * the document */ public static void setAddNodeAttribute(Node node, String attributeName, String attributeValue, Document doc) { if (null == node) { return; } NamedNodeMap attributes = node.getAttributes(); Element element = (Element) node; if (null == attributes) { element.setAttributeNode(getAttribute(attributeName, attributeValue, doc)); } else { Node n = attributes.getNamedItem(attributeName); if (null == n) { element.setAttributeNode(getAttribute(attributeName, attributeValue, doc)); } else { n.setNodeValue(attributeValue); } } }
From source file:Main.java
/** * Compares the attributes of two XML <code>Node</code> objects. This method * returns <code>true</code> if all attribute name-value pairs match * disregarding their order of placement. * //from w w w. ja v a 2s. c o m * @param n1 first <code>Node</code> * @param n2 second <code>Node</code> * * @return boolean * */ public static boolean diffAttributes(Node n1, Node n2) { NamedNodeMap n1Atts = n1.getAttributes(); NamedNodeMap n2Atts = n2.getAttributes(); if (n1Atts.getLength() != n2Atts.getLength()) { return false; } for (int i = 0; i < n1Atts.getLength(); i++) { Node a1 = n1Atts.item(i); Node a2Val = n2Atts.getNamedItem(a1.getNodeName()); if (a2Val == null || !a1.getNodeValue().equals(a2Val.getNodeValue())) { return false; } } return true; }
From source file:jp.go.nict.langrid.client.soap.io.SoapResponseParser.java
private static Node findFirstDescendantHasAttr(Node parent, String attrName, String attrValue) { if (parent == null) return null; Node n = parent.getFirstChild(); while (n != null) { NamedNodeMap attrs = n.getAttributes(); if (attrs != null) { Node attr = attrs.getNamedItem(attrName); if (attr != null) { if (attr.getNodeValue().equals(attrValue)) { return n; }//from w w w. j a v a 2s . co m } } Node d = findFirstDescendantHasAttr(n, attrName, attrValue); if (d != null) { return d; } n = n.getNextSibling(); } return n; }
From source file:Main.java
private static boolean hasEqualAttributes(Node arg0, Node arg) { NamedNodeMap map1 = arg0.getAttributes(); NamedNodeMap map2 = arg.getAttributes(); int len = map1.getLength(); if (len != map2.getLength()) { return false; }/*from ww w .j a v a 2s.c o m*/ for (int i = 0; i < len; i++) { Node n1 = map1.item(i); if (n1.getNodeName() != null) { Node n2 = map2.getNamedItem(n1.getNodeName()); if (n2 == null) { return false; } else if (!n1.getNodeValue().equals(n2.getNodeValue())) { return false; } } } return true; }
From source file:de.matzefratze123.heavyspleef.util.I18NNew.java
private static void readEntry(Node node, String parentEntry) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node childNode = list.item(i); String nodeName = childNode.getNodeName(); if (nodeName.equalsIgnoreCase(MESSAGE_ENTRY)) { NamedNodeMap attributes = childNode.getAttributes(); Node idNode = attributes.getNamedItem(ID_ATTRIBUTE); if (idNode == null) { Logger.warning("Warning: No id for message in " + MESSAGES_FILE + ". Ignoring message..."); continue; }/*from ww w. ja va 2 s . c om*/ String id = idNode.getNodeValue(); String value = childNode.getTextContent(); messages.put(parentEntry + id, value); } else if (nodeName.equalsIgnoreCase(ENTRY_ENTRY)) { NamedNodeMap attributes = childNode.getAttributes(); Node nameNode = attributes.getNamedItem(ENTRY_NAME); String entryName = nameNode.getNodeValue(); readEntry(childNode, parentEntry + entryName + "."); } } }
From source file:com.jaeksoft.searchlib.util.XPathParser.java
private final static String getAttributeString(Node node, String attributeName, boolean unescapeXml) { NamedNodeMap attr = node.getAttributes(); if (attr == null) return null; Node n = attr.getNamedItem(attributeName); if (n == null) return null; String t = n.getTextContent(); if (t == null) return null; return unescapeXml ? StringEscapeUtils.unescapeXml(t) : t; }
From source file:DomUtil.java
public static String getAttribute(Node element, String attName) { NamedNodeMap attrs = element.getAttributes(); if (attrs == null) return null; Node attN = attrs.getNamedItem(attName); if (attN == null) return null; return attN.getNodeValue(); }
From source file:it.polimi.diceH2020.plugin.control.JSonReader.java
private static boolean findAttribute(NamedNodeMap element, String attribute) { Boolean result = false;//from w ww. ja v a 2 s . c om try { Node value = element.getNamedItem(attribute); if (value != null) { result = true; } } catch (Exception e) { } return result; }