List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:Main.java
public static void setAttributeValue(Node node, String attribute, String value) { NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node nameAttr = attributes.getNamedItem(attribute); if (nameAttr != null) { nameAttr.setNodeValue(value); }//w ww . java2 s .c o m } }
From source file:Main.java
/** * Gets an attribute value or an empty string if not found * //from ww w .java 2s . c o m * @param node Node with the attribute * @param attrName Name of the attribute * @return Value of the attribute or empty string if not found */ public static String getAttribute(Node node, String attrName) { NamedNodeMap attributes = node.getAttributes(); if (attributes == null) return ""; Node attr = attributes.getNamedItem(attrName); if (attr != null) { return attr.getNodeValue(); } else { return ""; } }
From source file:Main.java
public static String getAttributeValue(Node node, String attribute) { NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node nameAttr = attributes.getNamedItem(attribute); if (nameAttr != null) { return nameAttr.getNodeValue(); }/*from w w w.j a va 2 s .c o m*/ } return null; }
From source file:Main.java
/** Helper methods - gets the <I>Attr</I> <I>Node</I> object from a <I>NamedNodeMap</I> of attributes. @param pNodeMap The <I>NamedNodeMap</I>. @param strName Name of the attribute. @return An <I>Attr</I> object. *///from www.ja va 2 s . com public static Attr getAttribute(NamedNodeMap pNodeMap, String strName) throws ClassCastException { Node pReturn = pNodeMap.getNamedItem(strName); if ((null == pReturn) || (pReturn instanceof Attr)) return (Attr) pReturn; throw new ClassCastException("The node retrieved from the NamedNodeMap is not an Attr object."); }
From source file:Main.java
public static String getAttribute(Node node, String name) { NamedNodeMap m = node.getAttributes(); if (m == null) return null; Node att = m.getNamedItem(name); if (att == null) return null; return att.getNodeValue(); }
From source file:Main.java
public static void updateUserMgtXML(File userMgtXML, String jndiConfigNameUserDB) throws Exception { Document doc = initializeXML(userMgtXML); NodeList configNodeList = doc.getElementsByTagName("Configuration"); Node configNode = configNodeList.item(0); //get the 0 index, since only one available NodeList nodeList = configNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equalsIgnoreCase("Property")) { if (node.hasAttributes()) { NamedNodeMap namedNodeMap = node.getAttributes(); Node attr = namedNodeMap.getNamedItem("name"); if (attr != null && attr.getNodeValue().equalsIgnoreCase("dataSource")) { node.setTextContent(jndiConfigNameUserDB); }//from w w w . ja v a 2 s . c o m } } } } finalizeXML(userMgtXML, doc, 4); }
From source file:Main.java
public static String getNodeAttributeValue(Node node, String attrName) { NamedNodeMap attrs = node.getAttributes(); if (attrs == null) return (null); Node value = attrs.getNamedItem(attrName); if (value == null) return (null); return (value.getNodeValue()); }
From source file:Main.java
/** * @param n Node to examine/*from w ww . ja va2 s.c o m*/ * @param attr Attribute to look for * @return true if the Node contains the named Attribute */ public static boolean hasAttribute(Node n, String attr) { NamedNodeMap attrs = n.getAttributes(); if (attrs == null) { return false; } Node ret = attrs.getNamedItem(attr); return ret != null; }
From source file:Main.java
public static final Node getSubNodeById(Node n, String id) { int i;/* w w w . j a v a 2 s .com*/ NodeList children; Node childnode; if (n == null) { return null; } children = n.getChildNodes(); for (i = 0; i < children.getLength(); i++) { childnode = children.item(i); NamedNodeMap nnm = childnode.getAttributes(); if (nnm != null) { Node attr = nnm.getNamedItem("id"); if (attr != null && id.equals(attr.getNodeValue())) { return childnode; } } childnode = getSubNodeById(childnode, id); if (childnode != null) { return childnode; } } return null; }
From source file:Main.java
/** * Get string value of specified attribute. Return null if attribute isn't defined. * @param attribs NamedNodeMap//ww w.j av a 2 s. com * @param attributeName String * @return String * @throws DOMException */ public static String getAttributeValue(NamedNodeMap attribs, String attributeName) throws DOMException { String value = null; if (attribs.getNamedItem(attributeName) != null) { value = attribs.getNamedItem(attributeName).getNodeValue(); } return value; }