List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:Main.java
/** * Get all direct child elements with a given name, for a parent element. * @param e/* w w w . ja v a 2 s.c om*/ * @return */ public static List<Element> getChildElements(Element e, String name) { if (e == null) return null; List<Element> result = new LinkedList<Element>(); NodeList list = e.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n instanceof Element) { if (name == null || name.equals(n.getLocalName()) || n.getLocalName().endsWith(":" + name)) { result.add((Element) n); } } } return result; }
From source file:Main.java
public static void removeNamespaceDeclarations(Node node, String... namespaces) { NamedNodeMap namedNodeMap = ((Element) node).getAttributes(); for (int nameIndex = 0; nameIndex < namedNodeMap.getLength(); nameIndex++) { Node namedNode = namedNodeMap.item(nameIndex); String uri = namedNode.getNamespaceURI(); String localName = namedNode.getLocalName(); if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) { for (String removeableNamespace : namespaces) { if (namedNode.getNodeValue().equals(removeableNamespace)) { ((Element) node).removeAttributeNS("http://www.w3.org/2000/xmlns/", localName); nameIndex--;/* w ww. java2 s .co m*/ } } } } }
From source file:Main.java
public static List<Node> getChildElementsByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); List<Node> childEles = new ArrayList<Node>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { childEles.add(node);/*from w w w.ja v a 2 s. com*/ } } return childEles; }
From source file:Main.java
public static Element getChildElementByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { return (Element) node; }//from ww w.ja va 2 s.c om } return null; }
From source file:Main.java
/** * Retrieves the local name of the given Node * /*from w w w . j a va 2s.co m*/ * @param n the Node * @return the local name String **/ public final static String getLocalName(final Node n) { if (n == null) { return null; } final String name = n.getLocalName(); return name == null ? getLocalName(n.getNodeName()) : name; }
From source file:Main.java
/** * Find a Node with a given QName/* w w w . j a va 2s . c o m*/ * * @param node parent node * @param name QName of the child we need to find * @return child node */ public static Node findNode(Node node, QName name) { if (name.getNamespaceURI().equals(node.getNamespaceURI()) && name.getLocalPart().equals(node.getLocalName())) return node; NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node ret = findNode(children.item(i), name); if (ret != null) return ret; } return null; }
From source file:Main.java
/** * Get the local name of a node (that may have a prefix). * /* ww w .j av a2 s.co m*/ * @param name The node (normally a DOM Element). * @return The local part of the name. */ public static String localName(Node node) { if (node == null) return null; String name = node.getLocalName(); if (name == null || name.length() <= 0) return localName(node.getNodeName()); return name; }
From source file:Main.java
public static List<String> getChildListValuesByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); List<String> childEles = new ArrayList<String>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { childEles.add(getTextValue((Element) node)); }// w w w . j a v a 2s.c o m } return childEles; }
From source file:Main.java
/** * Finds a Node with a given QNameb.// w ww .jav a2 s . c om * * @param node parent node * @param name QName of the child we need to find * @return Returns child node. */ public static Node findNode(Node node, QName name) { if (name.getNamespaceURI().equals(node.getNamespaceURI()) && name.getLocalPart().equals(node.getLocalName())) { return node; } NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node ret = findNode(children.item(i), name); if (ret != null) { return ret; } } return null; }
From source file:Main.java
public static Map<String, Object> getPropertiesWithValuesFromXML(Node propNode) { Map<String, Object> propertiesWithValues = new HashMap<String, Object>(); NodeList childList = propNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { String nodeName = currentNode.getLocalName(); String namespace = currentNode.getNamespaceURI(); // href is a live property which is handled differently String fqn = namespace + ":" + nodeName; propertiesWithValues.put(fqn, nodeValue(currentNode)); }// ww w. ja v a 2s.c om } return propertiesWithValues; }