List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:Main.java
public static Node getChildNode(Node node, String childTag) { if (node == null) return null; NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode != null && childNode.getLocalName() != null && childNode.getLocalName().equals(childTag)) { return childNode; }//from w w w. j av a 2s .co m } return null; }
From source file:Main.java
private static boolean nodeNameMatch(Node node, Collection<?> desiredNames) { return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName())); }
From source file:Main.java
private static String getValueByTagName(Node n, String tag) { if (n == null) return null; if (tag.equals(n.getLocalName())) return n.getFirstChild().getNodeValue(); if (n.hasChildNodes()) return getValueByTagName(n.getFirstChild(), tag); else if (n.getNextSibling() != null) return getValueByTagName(n.getNextSibling(), tag); else/*from w w w . j a v a 2s. c om*/ return getValueByTagName(n.getParentNode().getNextSibling(), tag); }
From source file:Main.java
static List<Node> children(Node parent, String childNS, String... childLocalName) { List<String> childNames = Arrays.asList(childLocalName); ArrayList<Node> result = new ArrayList<Node>(); NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (childNS.equals(child.getNamespaceURI()) && childNames.contains(child.getLocalName())) { result.add(child);//from w w w. ja v a2 s . c o m } } return result; }
From source file:Main.java
private static boolean nodeNameMatch(Node node, String desiredName) { return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName())); }
From source file:Main.java
public static void printAttributes(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); System.err.println("## prefix=" + node.getPrefix() + " localname:" + node.getLocalName() + " value=" + node.getNodeValue());//from w w w . jav a 2 s. com } }
From source file:Main.java
public static Element getChildElementByTagNameNS(Element parent, String tagName, String nsName) { NodeList nl = parent.getChildNodes(); int size = nl.getLength(); for (int i = 0; i < size; i++) { Node node = nl.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (tagName.equals(node.getLocalName())) { String ns = node.getNamespaceURI(); if (ns != null && ns.equals(nsName)) { return (Element) node; }/*from w w w .jav a 2s .co m*/ } } } return null; }
From source file:Main.java
private static boolean nodeNameMatch(Node node, Collection desiredNames) { return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName())); }
From source file:Main.java
/** * This method searches children of Element element for element with tagName * and namespaceURI nsName. It searchs one level down only. * //from w w w .j a v a 2 s . c om * @param element * The root element * @param nsName * NamespaceURI * @param tagName * A String representing the name of the tag to be searched for. * @return A List of elements that meet the criterial. */ public static List getElementsByTagNameNS1(Element element, String nsName, String tagName) { List list = new ArrayList(); if (element != null) { NodeList nl = element.getChildNodes(); int length = nl.getLength(); for (int i = 0; i < length; i++) { Node child = nl.item(i); String childName = child.getLocalName(); String childNS = child.getNamespaceURI(); if ((childName != null) && (childName.equals(tagName)) && (childNS != null) && (childNS.equals(nsName))) { list.add(child); } } } return list; }
From source file:Main.java
public static Node findSubElement(Node parent, String localName) { if (parent == null) { return null; }//from w w w.ja v a 2 s . c o m Node child = parent.getFirstChild(); while (child != null) { if ((child.getNodeType() == Node.ELEMENT_NODE) && (child.getLocalName().equals(localName))) { return child; } child = child.getNextSibling(); } return null; }