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

Here you can find the source of isAppropriateElement(final Node iNode, final String iNodeName, final 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(final Node iNode, final String iNodeName, final String iNamespace) 

Method Source Code

//package com.java2s;
/*// w w w .j  a  va  2s . c  o m
 * Copyright (c) [yyyy] [TITULAR]
 * This file is part of [SSSSS].  
 * 
 * [SSSS] is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version.
 * 
 * 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 GNU 
 * General Public License for more details, currently published 
 * at http://www.gnu.org/copyleft/gpl.html or in the gpl.txt in 
 * the root folder of this distribution.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
 * 02110-1301, USA.  
 */

import org.w3c.dom.*;

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(final Node iNode, final String iNodeName, final 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. getNamespaceDeclarationOrNull(String localName, Element element)
  2. getNamespaceForPrefix(String prefix, Element element)
  3. getNamespaceURI(Element element, String prefix)
  4. getNamespaceUriDeclaration(Element ele)
  5. getRequiredNamespaceDeclaration(String localName, Element element)
  6. isSameElement(final String namespace, final String localName, final XMLStreamReader reader)
  7. resolveNamespacePrefix(String prefix, Element element)
  8. writeEndElement(XMLStreamWriter out, String prefix, String namespaceURI)
  9. writeStartElement(XMLStreamWriter writer, String prefix, String namespaceURI, String nodeName)