List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:Main.java
public static Element getFirstChildElementNS(Element elm, String tns, String localName) { if (tns == null && localName == null) return getFirstChildElement(elm); if (tns == null || tns.length() == 0) return getFirstChildElement(elm, localName); NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node node = nl.item(c); if (node.getNodeType() != Node.ELEMENT_NODE) continue; if (localName == null && tns.equals(node.getNamespaceURI())) return (Element) node; if (localName != null && tns.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) return (Element) node; }/* w w w.j a va2 s .c o m*/ return null; }
From source file:Main.java
public static Element getFirstChildElementNS(Element elm, String tns, String localName) { if (tns == null && localName == null) return getFirstChildElement(elm); if (tns == null) return getFirstChildElement(elm, localName); NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node node = nl.item(c); if (node.getNodeType() != Node.ELEMENT_NODE) continue; if (localName == null && tns.equals(node.getNamespaceURI())) return (Element) node; if (localName != null && tns.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) return (Element) node; }//from w w w .ja v a 2 s . co m return null; }
From source file:ee.ria.xroad.proxyui.WSDLParser.java
private static String getChildValue(String childName, Element element) { if (element == null) { return null; }//from w w w . j a v a2s . co m NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (childName.equals(node.getLocalName())) { return getValue(node); } } return null; }
From source file:Main.java
/** Finds and returns the last child node with the given qualified name. */ public static Element getLastChildElementNS(Node parent, String[][] elemNames) { // search for node Node child = parent.getLastChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { for (int i = 0; i < elemNames.length; i++) { String uri = child.getNamespaceURI(); if (uri != null && uri.equals(elemNames[i][0]) && child.getLocalName().equals(elemNames[i][1])) { return (Element) child; }/*w w w .j a v a 2 s . c o m*/ } } child = child.getPreviousSibling(); } // not found return null; }
From source file:Main.java
/** Finds and returns the first child node with the given qualified name. */ public static Element getFirstChildElementNS(Node parent, String[][] elemNames) { // search for node Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { for (int i = 0; i < elemNames.length; i++) { String uri = child.getNamespaceURI(); if (uri != null && uri.equals(elemNames[i][0]) && child.getLocalName().equals(elemNames[i][1])) { return (Element) child; }//ww w .ja v a2s . c o m } } child = child.getNextSibling(); } // not found return null; }
From source file:Main.java
/** Finds and returns the next sibling node with the given qualified name. */ public static Element getNextSiblingElementNS(Node node, String[][] elemNames) { // search for node Node sibling = node.getNextSibling(); while (sibling != null) { if (sibling.getNodeType() == Node.ELEMENT_NODE) { for (int i = 0; i < elemNames.length; i++) { String uri = sibling.getNamespaceURI(); if (uri != null && uri.equals(elemNames[i][0]) && sibling.getLocalName().equals(elemNames[i][1])) { return (Element) sibling; }/*from ww w. ja v a 2 s . c o m*/ } } sibling = sibling.getNextSibling(); } // not found return null; }
From source file:Main.java
/** * Gets Nodes basic information such as Node name, type, value, namespace * <p/>/*from www . j a v a 2 s . co m*/ * and local name */ public static String getNodeBasics(Node node) { StringBuffer sb = new StringBuffer(); if (node == null) { sb.append(" Null node"); return sb.toString(); } sb.append(" Node[Namespace URI=" + node.getNamespaceURI() + " localname=" + node.getLocalName() + " name=" + node.getNodeName() + " type=" + getNodeTypeStr(node.getNodeType()) + " Value=" + node.getNodeValue() + "]"); return sb.toString(); }
From source file:Main.java
/** * Builds an XPointer that refers to the given node. If a shorthand pointer * (using a schema-determined identifier) cannot be constructed, then a * scheme-based pointer is derived that indicates the absolute location path * of a node in a DOM document. The location is specified as a scheme-based * XPointer having two parts://from w w w . j av a 2s .co m * <ul> * <li>an xmlns() part that declares a namespace binding context;</li> * <li>an xpointer() part that includes an XPath expression using the * abbreviated '//' syntax for selecting a descendant node.</li> * </ul> * * @param node * A node in a DOM document. * @return A String containing either a shorthand or a scheme-based pointer * that refers to the node. * * @see <a href="http://www.w3.org/TR/xptr-framework/"target="_blank"> * XPointer Framework</a> * @see <a href="http://www.w3.org/TR/xptr-xmlns/" target="_blank">XPointer * xmlns() Scheme</a> * @see <a href="http://www.w3.org/TR/xptr-xpointer/" * target="_blank">XPointer xpointer() Scheme</a> */ public static String buildXPointer(Node node) { if (null == node) { return ""; } StringBuilder xpointer = new StringBuilder(); if (null != node.getAttributes() && null != node.getAttributes().getNamedItem("id")) { String id = node.getAttributes().getNamedItem("id").getNodeValue(); xpointer.append(node.getLocalName()).append("[@id='").append(id).append("']"); return xpointer.toString(); } String nsURI = node.getNamespaceURI(); String nsPrefix = node.getPrefix(); if (null == nsPrefix) nsPrefix = "tns"; // WARNING: Escaping rules are currently ignored. xpointer.append("xmlns(").append(nsPrefix).append("=").append(nsURI).append(")"); xpointer.append("xpointer(("); switch (node.getNodeType()) { case Node.ELEMENT_NODE: // Find the element in the list of all similarly named descendants // of the document root. NodeList elementsByName = node.getOwnerDocument().getElementsByTagNameNS(nsURI, node.getLocalName()); for (int i = 0; i < elementsByName.getLength(); i++) { if (elementsByName.item(i).isSameNode(node)) { xpointer.append("//"); xpointer.append(nsPrefix).append(':').append(node.getLocalName()).append(")[").append(i + 1) .append("])"); break; } } break; case Node.DOCUMENT_NODE: xpointer.append("/"); break; case Node.ATTRIBUTE_NODE: Attr attrNode = (Attr) node; xpointer = new StringBuilder(buildXPointer(attrNode.getOwnerElement())); xpointer.insert(xpointer.lastIndexOf(")"), "/@" + attrNode.getName()); break; default: xpointer.setLength(0); break; } return xpointer.toString(); }
From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java
private static void parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) { if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { if ("property".equals(node.getNodeName()) || "property".equals(node.getLocalName())) { String name = ((Element) node).getAttribute("name"); if (name != null && name.length() > 0) { String value = ((Element) node).getAttribute("value"); String ref = ((Element) node).getAttribute("ref"); if (value != null && value.length() > 0) { beanDefinition.getPropertyValues().addPropertyValue(name, value); } else if (ref != null && ref.length() > 0) { beanDefinition.getPropertyValues().addPropertyValue(name, new RuntimeBeanReference(ref)); } else { throw new UnsupportedOperationException("Unsupported <property name=\"" + name + "\"> sub tag, Only supported <property name=\"" + name + "\" ref=\"...\" /> or <property name=\"" + name + "\" value=\"...\" />"); }/* www . jav a 2 s . c o m*/ } } } } } }
From source file:Main.java
/** * Searches for a node within a DOM document with a given node path expression. * Elements are separated by '.' characters. * Example: Foo.Bar.Poo/*from w w w. java 2 s . c o m*/ * @param doc DOM Document to search for a node. * @param pathExpression dot separated path expression * @return Node element found in the DOM document. */ public static Node findNodeByName(Document doc, String pathExpression) { final StringTokenizer tok = new StringTokenizer(pathExpression, "."); final int numToks = tok.countTokens(); NodeList elements; if (numToks == 1) { elements = doc.getElementsByTagNameNS("*", pathExpression); return elements.item(0); } String element = pathExpression.substring(pathExpression.lastIndexOf('.') + 1); elements = doc.getElementsByTagNameNS("*", element); String attributeName = null; if (elements.getLength() == 0) { //No element found, but maybe we are searching for an attribute attributeName = element; //cut off attributeName and set element to next token and continue Node found = findNodeByName(doc, pathExpression.substring(0, pathExpression.length() - attributeName.length() - 1)); if (found != null) { return found.getAttributes().getNamedItem(attributeName); } else { return null; } } StringBuffer pathName; Node parent; for (int j = 0; j < elements.getLength(); j++) { int cnt = numToks - 1; pathName = new StringBuffer(element); parent = elements.item(j).getParentNode(); do { if (parent != null) { pathName.insert(0, '.'); pathName.insert(0, parent.getLocalName());//getNodeName()); parent = parent.getParentNode(); } } while (parent != null && --cnt > 0); if (pathName.toString().equals(pathExpression)) { return elements.item(j); } } return null; }