Java XML Element Get Value getXMLIdentifier(Element element)

Here you can find the source of getXMLIdentifier(Element element)

Description

Generates a unique string from the supplied element's name space URI and tag name.

License

Open Source License

Parameter

Parameter Description
element The element to generate the identifier for.

Exception

Parameter Description
NullPointerException If supplied element is <code>null</code>.

Return

A unique string from the supplied element's name space URI and tag name.

Declaration

public static String getXMLIdentifier(Element element) throws NullPointerException 

Method Source Code

//package com.java2s;
/*--------------------------------------------------------------------------
 * Copyright (c) 2004, 2006-2007 OpenMethods, LLC
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* www .ja va 2 s .  co  m*/
 *    Trip Gilman (OpenMethods), Lonnie G. Pryor (OpenMethods)
 *    - initial API and implementation
 -------------------------------------------------------------------------*/

import org.w3c.dom.Element;

public class Main {
    /**
     * Generates a unique string from the supplied element's name space URI and
     * tag name.
     * 
     * @param element The element to generate the identifier for.
     * @return A unique string from the supplied element's name space URI and tag
     *         name.
     * @throws NullPointerException If supplied element is <code>null</code>.
     */
    public static String getXMLIdentifier(Element element) throws NullPointerException {
        if (element == null)
            throw new NullPointerException("element"); //$NON-NLS-1$
        return getQualifiedIdentifier(element.getLocalName(), element.getNamespaceURI());
    }

    /**
     * Generates a unique string from the supplied qualifier and identifier.
     * 
     * @param identifier The identifier to be qualified.
     * @param qualifier The qualifier of the identifier.
     * @return A unique string from the supplied name space and identifier.
     * @throws NullPointerException If supplied identifier is <code>null</code>.
     * @throws NullPointerException If supplied qualifier is <code>null</code>.
     */
    public static String getQualifiedIdentifier(String identifier, String qualifier) throws NullPointerException {
        if (qualifier == null)
            throw new NullPointerException("qualifier"); //$NON-NLS-1$
        if (identifier == null)
            throw new NullPointerException("identifier"); //$NON-NLS-1$
        return new StringBuffer(identifier.length() + 1 + qualifier.length()).append(identifier).append(':')
                .append(qualifier).toString();
    }
}

Related

  1. getXmlBoolean(Element element, String name)
  2. getXMLContent(XMLEventReader reader, StartElement element, boolean decodeCharacters)
  3. getXmlElementAnnotation(Field field)
  4. getXmlElementDecl(Method method)
  5. getXMLElementTextValue(Element element, String tagName)
  6. getXMLText(Element element)