Java XML Element Get Value getTagElement(Element node, String key)

Here you can find the source of getTagElement(Element node, String key)

Description

get Tag Element

License

Open Source License

Declaration

private static Element getTagElement(Element node, String key) 

Method Source Code

//package com.java2s;
/**//  w  w w  .  j a  v a 2 s  .co m
   Licensed under the GNU General Public License version 3
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.gnu.org/licenses/gpl-3.0.html
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
    
**/

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    private static Element getTagElement(Element node, String key) {
        NodeList childs = node.getChildNodes();
        for (int t = 0; t < childs.getLength(); t++) {
            Node attNode = childs.item(t);
            if (attNode.getAttributes() != null) {
                if (attNode.getAttributes().getNamedItem("k").getNodeValue().equals(key)) {
                    return (Element) attNode;
                }
            }
        }
        return null;
    }
}

Related

  1. getTagLocalName(final Element element)
  2. getTagNameIgnorePrefix(Element element)
  3. getTagText(Element ele)
  4. getTagValue(Element e)