Here you can find the source of getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag)
Parameter | Description |
---|---|
contextNode | where to start the search |
nsuri | the namespace uri |
tag | the local name part of the wanted child |
public static Node getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag)
//package com.java2s; /*//from w ww.j a v a 2 s .c o m * Copyright (c) 2012. betterFORM Project - http://www.betterform.de * Licensed under the terms of BSD License */ import org.w3c.dom.*; public class Main { /** * returns the first child of the contextnode which has the specified tagname and namespace uri regardless of the * depth in the tree. * * @param contextNode where to start the search * @param nsuri the namespace uri * @param tag the local name part of the wanted child * @return the first child found under the contextnode */ public static Node getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag) { Node n = null; if (contextNode.getNodeType() == Node.DOCUMENT_NODE) { n = ((Document) contextNode).getDocumentElement(); if (!(n.getNamespaceURI().equals(nsuri) && n.getNodeName().equals(tag))) { n = null; } } else { NodeList nodes = ((Element) contextNode).getElementsByTagNameNS(nsuri, tag); if (nodes != null) { n = nodes.item(0); } } return n; } }