List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:Main.java
/** * Gets value of an attribute from node// w w w .jav a 2 s. co m * * @param node * Node Object * @param attributeName * Attribute Name * @return Attribute Value * @throws IllegalArgumentException * for Invalid input */ public static String getAttribute(final Node node, final String attributeName) throws IllegalArgumentException { // Validate attribute name if (attributeName == null) { throw new IllegalArgumentException("Attribute Name cannot be null in XmlUtils.getAttribute method"); } // Validate node if (node == null) { throw new IllegalArgumentException( "Node cannot be null in XmlUtils.getAttribute method for attribute name:" + attributeName); } final NamedNodeMap attributeList = node.getAttributes(); if (attributeList != null) { final Node attribute = attributeList.getNamedItem(attributeName); return attribute == null ? null : ((Attr) attribute).getValue(); } else { return null; } }
From source file:Main.java
public static String getAttrValue(NamedNodeMap attrs, String attrName) { if (attrs == null || attrName == null) { return null; }//from w w w.ja v a 2 s.co m String attrValue = null; Node attrNode = attrs.getNamedItem(attrName); if (attrNode == null || Node.ATTRIBUTE_NODE != attrNode.getNodeType()) { return null; } attrValue = attrNode.getNodeValue(); return attrValue; }
From source file:org.aectann.postage.TrackingStatusRefreshTask.java
public static TrackingInfo syncRequest(Context context, String tracking) throws FactoryConfigurationError { TrackingInfo result = null;//from w w w.j a va 2 s . c o m if (tracking != null && tracking.length() > 0) { tracking = tracking.toUpperCase(); HttpClient client = new DefaultHttpClient(); try { HttpResponse response = client.execute(new HttpGet("http://prishlo.li/" + tracking + ".xml")); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { InputStream content = response.getEntity().getContent(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(content); String weight = getFirstVaueOrNull(document, "weight"); String from = getFirstVaueOrNull(document, "from"); String kind = getFirstVaueOrNull(document, "kind"); TrackingInfo old = TrackingStorageUtils.loadStoredTrackingInfo(tracking, context); result = new TrackingInfo(old != null ? old.getName() : null, tracking, weight, kind, from); NodeList checkpoints = document.getElementsByTagName("checkpoint"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); for (int i = 0; i < checkpoints.getLength(); i++) { Node current = checkpoints.item(i); NamedNodeMap attributes = current.getAttributes(); Node state = attributes.getNamedItem("state"); Node attribute = attributes.getNamedItem("attribute"); Node date = attributes.getNamedItem("date"); String dateString = date.getNodeValue(); String attributeString = attribute.getNodeValue(); String stateString = state.getNodeValue(); String locationString = current.getFirstChild().getNodeValue(); result.addStatus(new TrackingStatus(stateString, dateFormat.parse(dateString), attributeString, locationString)); } } } catch (Exception e) { if (result == null) { result = new TrackingInfo(null, tracking, null, null, null); } } } return result; }
From source file:Main.java
public static void removeAttribute(Node parent, String name, String value, boolean recursive) { NamedNodeMap nnm = parent.getAttributes(); if (nnm != null) { if (value == null) { nnm.removeNamedItem(name);/*from www . j ava2s . c om*/ } else { Node attr = nnm.getNamedItem(name); if (attr != null) { String attrVal = attr.getNodeValue(); if (value.equals(attrVal)) { nnm.removeNamedItem(name); } } } } if (recursive) { for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { removeAttribute(child, name, value, recursive); } } }
From source file:Main.java
public static String[] getAttributes(final Node node, final String[] attributeNames) { final String[] valueList = new String[attributeNames.length]; final NamedNodeMap attMap = node.getAttributes(); Node tmpNode = null;/*from w ww .j a v a 2s . c o m*/ for (int i = 0; i < attributeNames.length; i++) { try { tmpNode = attMap.getNamedItem(attributeNames[i]); valueList[i] = tmpNode.getNodeValue(); } catch (Exception e) { valueList[i] = ""; } } // next attribute return valueList; }
From source file:jp.go.nict.langrid.bpel.entity.PartnerLink.java
private static String getAttr(NamedNodeMap attrs, String name) { Node attr = attrs.getNamedItem(name); if (attr == null) return null; else// w w w .j a v a 2s. c om return attr.getNodeValue(); }
From source file:Main.java
/** * @param n Node to examine//from ww w .j a va 2s . com * @param attr Attribute to look for * @param def Default value to return if attribute is not present * @return if the Node contains the named Attribute, the value, if not, the * def parameter */ public static String getAttribute(Node n, String attr, String def) { NamedNodeMap attrs = n.getAttributes(); if (attrs == null) { return def; } Node ret = attrs.getNamedItem(attr); if (ret == null) { return def; } else { return ret.getNodeValue(); } }
From source file:eu.planets_project.services.utils.cli.CliMigrationPaths.java
private static URI decodeURI(Node uri) throws URISyntaxException { NamedNodeMap attrs = uri.getAttributes(); Node item = attrs.getNamedItem("value"); String urivalue = item.getNodeValue(); return new URI(urivalue); }
From source file:com.tascape.qa.th.android.model.UIA.java
public static UIANode parseNode(Node node) { if (!node.getNodeName().equals(UIANode.TAG_NAME)) { return null; }/*from ww w .java 2s .c om*/ NamedNodeMap map = node.getAttributes(); String klass = map.getNamedItem("class").getNodeValue(); UIANode uiNode = newNode(klass); for (int i = 0, j = map.getLength(); i < j; i++) { Node attr = map.item(i); uiNode.setAttribute(attr.getNodeName(), attr.getNodeValue()); } NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { UIANode n = parseNode(nl.item(i)); if (n == null) { continue; } uiNode.addNode(n); } return uiNode; }
From source file:com.autentia.tnt.xml.UtilitiesXML.java
/** * Devuelve el valor del atributo "nombre" de un nodo * @param nombre//from www . jav a 2 s. c om * @param nodo * @return */ public static String giveAttributeNode(String name, Node node) { NamedNodeMap map = node.getAttributes(); String value = null; if (map != null) { Node nodoAt = map.getNamedItem(name); if (nodoAt != null) value = nodoAt.getNodeValue(); } return value; }