Java XML QName Create toQName(String namespaceUri, String qualifiedName)

Here you can find the source of toQName(String namespaceUri, String qualifiedName)

Description

Convert a namespace URI and DOM or SAX qualified name to a QName.

License

Apache License

Parameter

Parameter Description
namespaceUri the namespace URI
qualifiedName the qualified name

Return

a QName

Declaration

public static QName toQName(String namespaceUri, String qualifiedName) 

Method Source Code


//package com.java2s;
/*//from w  ww.ja  v a 2s  .c o  m
 * Copyright 2005-2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 javax.xml.namespace.QName;

public class Main {
    /** Indicates whether {@link QName} has a prefix. The first release of the class did not have this. */
    private static boolean qNameHasPrefix;

    /**
     * Convert a namespace URI and DOM or SAX qualified name to a <code>QName</code>. The qualified name can have the
     * form <code>prefix:localname</code> or <code>localName</code>.
     *
     * @param namespaceUri  the namespace URI
     * @param qualifiedName the qualified name
     * @return a QName
     */
    public static QName toQName(String namespaceUri, String qualifiedName) {
        int idx = qualifiedName.indexOf(':');
        if (idx == -1) {
            return new QName(namespaceUri, qualifiedName);
        } else {
            return createQName(namespaceUri, qualifiedName.substring(idx + 1), qualifiedName.substring(0, idx));
        }
    }

    /**
     * Creates a new <code>QName</code> with the given parameters. Sets the prefix if possible, i.e. if the
     * <code>QName(String, String, String)</code> constructor can be found. If this constructor is not available (as is
     * the case on older implementations of JAX-RPC), the prefix is ignored.
     *
     * @param namespaceUri namespace URI of the <code>QName</code>
     * @param localPart    local part of the <code>QName</code>
     * @param prefix       prefix of the <code>QName</code>. May be ignored.
     * @return the created <code>QName</code>
     * @see QName#QName(String,String,String)
     */
    public static QName createQName(String namespaceUri, String localPart, String prefix) {
        if (qNameHasPrefix) {
            return new QName(namespaceUri, localPart, prefix);
        } else {
            return new QName(namespaceUri, localPart);
        }
    }
}

Related

  1. getEmptyQName()
  2. string2qname(String name)
  3. stringToQName(String s)
  4. toQName(Map setProps)
  5. toQName(NamespaceContext namespaceContext, String qualifiedName)
  6. toQName(String s)
  7. toQNameArray(String[] array)