Java XML QName uriToQName(String uri)

Here you can find the source of uriToQName(String uri)

Description

uri To Q Name

License

Apache License

Declaration

public static QName uriToQName(String uri) 

Method Source Code

//package com.java2s;
/*/*  ww  w. jav  a  2s . c  o  m*/
 * Copyright (c) 2010-2013 Evolveum
 *
 * 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 {
    public static QName uriToQName(String uri) {

        if (uri == null) {
            throw new IllegalArgumentException("URI is null");
        }
        int index = uri.lastIndexOf("#");
        if (index != -1) {
            String ns = uri.substring(0, index);
            String name = uri.substring(index + 1);
            return new QName(ns, name);
        }
        index = uri.lastIndexOf("/");
        // TODO check if this is still in the path section, e.g.
        // if the matched slash is not a beginning of authority
        // section
        if (index != -1) {
            String ns = uri.substring(0, index + 1);
            String name = uri.substring(index + 1);
            return new QName(ns, name);
        }
        throw new IllegalArgumentException("The URI (" + uri + ") does not contain slash character");
    }
}

Related

  1. setValue(java.util.Map map, String name, String newValue)
  2. splitQName(String qualifiedName)
  3. stringToQName(XMLStreamReader reader, String text, String defaultNS)
  4. toJavaName(QName xmlName)
  5. uniqueQName(QName q)