Java XML Node Namespace isAppropriateElement(Node iNode, String iNodeName, String iNamespace)

Here you can find the source of isAppropriateElement(Node iNode, String iNodeName, String iNamespace)

Description

This method determins if a node in the DOM Tree (iNode) is the node we are looking for.

License

Open Source License

Parameter

Parameter Description
iNode The Node we are trying to determine if it is the correct node
iNodeName The name of the node we are looking for.
iNamespace The namespace of the node we are looking for.

Return

A boolean value indicating whether or not this is the correct node we are looking for

Declaration

public static boolean isAppropriateElement(Node iNode, String iNodeName, String iNamespace) 

Method Source Code

//package com.java2s;
/* Agrega es una federaci?n de repositorios de objetos digitales educativos formada por todas las Comunidades Aut?nomas propiedad de Red.es. Este c?digo ha sido desarrollado por la Entidad P?blica Empresarial red.es adscrita al Ministerio de Industria,Turismo y Comercio a trav?s de la Secretar?a de Estado de Telecomunicaciones y para la Sociedad de la Informaci?n, dentro del Programa Internet en el Aula, que se encuadra dentro de las actuaciones previstas en el Plan Avanza (Plan 2006-2010 para el desarrollo de la Sociedad de la Informaci?n y de Convergencia con Europa y entre Comunidades Aut?nomas y Ciudades Aut?nomas) y ha sido cofinanciado con fondos FEDER del Programa Operativo FEDER 2000-2006 ?Sociedad de la Informaci?n?
    //from w w w .  ja v a 2  s  .  c  o  m
This program is free software: you can redistribute it and/or modify it under the terms of the European Union Public Licence (EUPL v.1.0).  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the European Union Public Licence (EUPL v.1.0). You should have received a copy of the EUPL licence along with this program.  If not, see http://ec.europa.eu/idabc/en/document/7330.
*/

import org.w3c.dom.Node;

import org.w3c.dom.Attr;

public class Main {
    /**
     * This method determins if a node in the DOM Tree <code>(iNode)</code> is
     * the node we are looking for.  This is done by comparing the node's
     * local name and namespace with a given node name <code>(iNodeName)</code>
     * and namespace <code>(iNamespace)</code>.
     *
     * @param iNode The Node we are trying to determine if it is the correct
     *              node
     * @param iNodeName The name of the node we are looking for.
     * @param iNamespace The namespace of the node we are looking for.
     *
     * @return A boolean value indicating whether or not this is the
     *         correct node we are looking for
     */
    public static boolean isAppropriateElement(Node iNode, String iNodeName, String iNamespace) {

        boolean result = false;

        if (iNode.getNodeType() == Node.ATTRIBUTE_NODE) {
            if (iNode.getNamespaceURI() == null) {
                // Attribute has been passed in and its namepsace is null, get the
                // attributes parent's namespace
                String parentsNamespace = ((Attr) iNode).getOwnerElement().getNamespaceURI();
                if ((iNode.getLocalName().equals(iNodeName)) && (parentsNamespace.equals(iNamespace))) {
                    result = true;
                }
            } else {
                if ((iNode.getLocalName().equals(iNodeName)) && (iNode.getNamespaceURI().equals(iNamespace))) {
                    result = true;
                }
            }
        } else if ((iNode.getLocalName().equals(iNodeName)) && (iNode.getNamespaceURI().equals(iNamespace))) {
            result = true;
        }

        return result;
    }
}

Related

  1. hasDITANamespace(Node node)
  2. hasNamespace(Node node, String prefix, String namespace)
  3. hasNamespaceURI(@Nullable final Node aNode, @Nullable final String sNamespaceURI)
  4. hasNamespaceURI(@Nullable final Node aNode, @Nullable final String sNamespaceURI)
  5. isAppropriateElement(Node iNode, String iNodeName, String iNamespace)
  6. isInNamespace(Node node, String namespace)
  7. isInNamespace(Node node, String namespace)
  8. isNamespace(Node node)
  9. isNamespaceElement(Node node, String namespace)