Java XML Namespace getPrefixFromNamespaceDeclaration(String namespace)

Here you can find the source of getPrefixFromNamespaceDeclaration(String namespace)

Description

Returns any prefix declared with this namespace.

License

CDDL license

Declaration

public static String getPrefixFromNamespaceDeclaration(String namespace) 

Method Source Code


//package com.java2s;
/*//from  w w w  .  j a  v  a 2 s . com
 * The contents of this file are subject to the terms of the Common Development
 * and Distribution License (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
 * or http://www.netbeans.org/cddl.txt.
 *
 * When distributing Covered Code, include this CDDL Header Notice in each file
 * and include the License file at http://www.netbeans.org/cddl.txt.
 * If applicable, add the following below the CDDL Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 *
 * The Original Software is NetBeans. The Initial Developer of the Original
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

import javax.xml.XMLConstants;

public class Main {
    /**
     * Returns any prefix declared with this namespace. For example, if
     * the namespace was declared as xmlns:po, the prefix 'po' will be returned.
     * Returns null for declaration that contains no prefix.
     */
    public static String getPrefixFromNamespaceDeclaration(String namespace) {
        if (!namespace.startsWith(XMLConstants.XMLNS_ATTRIBUTE))
            return null;
        int xmlnsLength = XMLConstants.XMLNS_ATTRIBUTE.length();
        if (namespace.length() == xmlnsLength) {
            return ""; // NOI18N
        }
        if (namespace.charAt(xmlnsLength) == ':') {
            return namespace.substring(xmlnsLength + 1);
        }
        return null;
    }
}

Related

  1. getNamespaceCtx()
  2. getNamespacesForClass(final Class clazz)
  3. getNamespaceURI(Name name)
  4. getPackageNamespace(Class cls)
  5. getPrefix(final Package targetPackage, String namespaceURI)
  6. getRequestMessageType(String intfNamespace, String op, String prefix)
  7. getSchemaNamespace(Package pkg)
  8. getTEINamespaceContext()
  9. getXmlSchemaNamespace(Class clazz)