Java XML Namespace createNamespaceContext(final String nsPrefix, final String nsUri)

Here you can find the source of createNamespaceContext(final String nsPrefix, final String nsUri)

Description

create Namespace Context

License

LGPL

Declaration

public static NamespaceContext createNamespaceContext(final String nsPrefix, final String nsUri) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.Iterator;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;

public class Main {
    public static NamespaceContext createNamespaceContext(final String nsPrefix, final String nsUri) {

        return new NamespaceContext() {

            public String getNamespaceURI(String prefix) {
                if (prefix.equals(nsPrefix)) {
                    return nsUri;
                } else {
                    return XMLConstants.NULL_NS_URI;
                }//from w w  w.  j  ava 2  s.c  om
            }

            public String getPrefix(String namespace) {
                if (namespace.equals(nsUri)) {
                    return nsPrefix;
                } else {
                    return null;
                }
            }

            public Iterator<String> getPrefixes(String namespace) {
                return null;
            }

        };
    }
}

Related

  1. compile(String expression, NamespaceContext namespaceContext)
  2. createXMLReader(boolean validating, boolean namespaceAware)
  3. createXMLReader(boolean validating, boolean withNamespace)
  4. getBaseNamespace(InputStream owlStream)
  5. getBuilder(boolean ignoreComments, boolean validating, boolean ignoreContentWhitespace, boolean isNamespaceAware)