give a list of <tt>Nokogiri::XML::Namespace</tt> definitions, produce
 a Hash <tt>{prefix=>uri}</tt> of namespace bindings
174185
def namespace_bindings_from_defs(ns_defs)
      (ns_defs||[]).reduce({}) do |h,ns_def|
        h[ns_def.prefix||""] = ns_def.href
        h
      end
    end
22784
public function register_namespaces_for_xpath() {
        $scnam = $this->activemanifest->get_cc_namespaces();
        foreach ($scnam as $key => $value) {
            $this->registerNS($key, $value);
        }
    }
1051005
private Map<String, String> namespaces(Kam kam) {
        Map<String, String> nsmap = new HashMap<String, String>();

        // find namespaces in resource index
        List<NamespaceDescriptor> ns = nsrsvc.getAllNamespaceDescriptors();
        for (NamespaceDescriptor n : ns) {
            Namespace the_ns = n.getNamespace();
            nsmap.put(the_ns.getPrefix(), the_ns.getResourceLocation());
        }

        // then find namespaces identified by the KAM
        List<org.openbel.framework.api.internal.KAMStoreDaoImpl.Namespace> nsl =
                kAMStore.getNamespaces(kam);
        for (org.openbel.framework.api.internal.KAMStoreDaoImpl.Namespace kam_ns : nsl) {
            nsmap.put(kam_ns.getPrefix(), kam_ns.getResourceLocation());
        }
        return nsmap;
    }
888480
def xmlns(source):
    
    namespaces = {}
    events=("end", "start-ns", "end-ns")
    for (event, elem) in iterparse(source, events):
        if event == "start-ns":
            prefix, ns = elem
            namespaces[prefix] = ns
        elif event == "end":
            break

    # Reset stream
    if hasattr(source, "seek"):
        source.seek(0)

    return namespaces
648963
def find_namespace_uri(ns_stack, prefix, uri_check=nil)
      tns = ns_stack.reverse.find{|ns| ns.has_key?(prefix)}
      uri = tns[prefix] if tns
      raise "prefix: '#{prefix}' is bound to uri: '#{uri}', but should be '#{uri_check}'" if uri_check && uri && uri!=uri_check
      uri
    end
310026
def build_namespace(namespace)
      raise(TriplestoreAdapter::TriplestoreException, "build_namespace received blank namespace") if namespace.empty?
      request = Net::HTTP::Post.new("#{build_url}/blazegraph/namespace")
      request['Content-Type'] = 'text/plain'
      request.body = "com.bigdata.rdf.sail.namespace=#{namespace}"
      @http.request(@uri, request)
      "#{build_url}/blazegraph/namespace/#{namespace}/sparql"
    end
616381
def traverse(element, visitor, context = Visitor::Context.new)
      ns_bindings = namespace_bindings_from_defs(element.namespace_definitions)
      context.ns_stack.push(ns_bindings)

      eelement, eattrs = explode_element(element)

      begin
        visitor.element(context, eelement, eattrs, ns_bindings) do
          element.children.each do |child|
            if child.element?
              traverse(child, visitor, context)
            elsif child.text?
              visitor.text(context, child.content)
            else
              Rsxml.log{|logger| logger.warn("unknown Nokogiri Node type: #{child.inspect}")}
            end
          end
        end
      ensure
        context.ns_stack.pop
      end

      visitor
    end
593422
def nsdeclarations(self):
        
        s = []
        myns = None, self.expns
        if self.parent is None:
            pns = Namespace.default
        else:
            pns = None, self.parent.expns
        if myns[1] != pns[1]:
            if self.expns is not None:
                s.append(' xmlns="%s"' % (self.expns,))
        for item in self.nsprefixes.items():
            p, u = item
            if self.parent is not None:
                ns = self.parent.resolvePrefix(p)
                if ns[1] == u:
                    continue
            s.append(' xmlns:%s="%s"' % (p, u))
        return "".join(s)
1214039
def _namespace_from_uri(self, uri):
        """"""
        # TODO - this could be helped a bunch with proper use of the graph API
        # it seems a bit fragile to treat these as simple string-splits
        uri = str(uri)
        parts = uri.split('#')
        if len(parts) == 1:
            return "%s/" % '/'.join(uri.split('/')[:-1])
        return "%s#" % '#'.join(parts[:-1])
530023
def skin_namespace_hash(options = {})
      { 
        :match   =>  options[:match] ? options[:match] : /[\/]/, 
        :replace =>  options[:replace] ? options[:replace] : "_", 
        :prefix  =>  options[:prefix] ? options[:prefix] : nil,
        :root    =>  options[:root] ? options[:root] : "root"
      }
    end
410572
def build_prefixes(namespaces=None):
    
    if namespaces is None:
        namespaces = [
            ('bf', str(BIBFRAME)),
            ('schema', str(SCHEMA_ORG))
        ]
    output = "PREFIX {}: <{}>\n".format(
        namespaces[0][0],
        namespaces[0][1])
    if len(namespaces) == 1:
        return output
    else:
        for namespace in namespaces[1:]:
            output += "PREFIX  {}: <{}>\n".format(namespace[0], namespace[1])
    return output
556674
def epp_node(name, value = nil, namespaces = {})
      value, namespaces = nil, value if value.kind_of?(Hash)

      node = xml_node(name, value)
      node.namespaces.namespace = epp_namespace(node, nil, namespaces)
      node
    end
428940
def add(ns, element_name, value, attributes={})
      element = REXML::Element.new(element_name)
      if ns.is_a?(Namespace)
        unless ns.prefix.nil? || ns.prefix.empty?
          element.name = "#{ns.prefix}:#{element_name}"
          element.add_namespace ns.prefix, ns.uri unless @ns == ns || @ns == ns.uri
        else
          element.add_namespace ns.uri unless @ns == ns || @ns == ns.uri
        end
      else
        element.add_namespace ns unless @ns == ns || @ns.to_s == ns
      end
      if value.is_a?(Element)
        value.elem.each_element do |e|
          element.add e.deep_clone
        end
        value.elem.attributes.each_attribute do |a|
          unless a.name =~ /^xmlns(?:\:)?/
            element.add_attribute a
          end
        end
        #element.text = value.elem.text unless value.elem.text.nil?
        text = value.elem.get_text
        unless text.nil?
          element.text = REXML::Text.new(text.to_s, true, nil, true)
        end
      else
        if value.is_a?(REXML::Element)
          element.add_element value.deep_clone
        else
          element.add_text value.to_s
        end
      end
      element.add_attributes attributes unless attributes.nil?
      @elem.add_element element
    end
51542
def get_all_namespaces(offset=None, count=None, proxy=None, hostport=None):
    
    assert proxy or hostport, 'Need proxy or hostport'
    if proxy is None:
        proxy = connect_hostport(hostport)

    offset = 0 if offset is None else offset

    schema = {
        'type': 'object',
        'properties': {
            'namespaces': {
                'type': 'array',
                'items': {
                    'type': 'string',
                    'pattern': OP_NAMESPACE_PATTERN,
                },
            },
        },
        'required': [
            'namespaces'
        ],
    }

    namespaces_schema = json_response_schema(schema)

    resp = {}
    try:
        resp = proxy.get_all_namespaces()
        resp = json_validate(namespaces_schema, resp)
        if json_is_error(resp):
            return resp

    except ValidationError as e:
        if BLOCKSTACK_DEBUG:
            log.exception(e)

        resp = {'error': 'Server response did not match expected schema.  You are likely communicating with an out-of-date Blockstack node.', 'http_status': 502}
        return resp

    except socket.timeout:
        log.error("Connection timed out")
        resp = {'error': 'Connection to remote host timed out.', 'http_status': 503}
        return resp

    except socket.error as se:
        log.error("Connection error {}".format(se.errno))
        resp = {'error': 'Connection to remote host failed.', 'http_status': 502}
        return resp

    except Exception as ee:
        if BLOCKSTACK_DEBUG:
            log.exception(ee)

        log.error("Caught exception while connecting to Blockstack node: {}".format(ee))
        resp = {'error': 'Failed to contact Blockstack node.  Try again with `--debug`.', 'http_status': 500}
        return resp

    stride = len(resp['namespaces']) if count is None else offset + count
    return resp['namespaces'][offset:stride]
1372565
def _inclusiveNamespacePrefixes(node, context, unsuppressedPrefixes):
    ''''''
    inclusive = []
    if node.prefix:
        usedPrefixes = ['xmlns:%s' %node.prefix]
    else:
        usedPrefixes = ['xmlns']

    for a in _attrs(node):
        if a.nodeName.startswith('xmlns') or not a.prefix: continue
        usedPrefixes.append('xmlns:%s' %a.prefix)

    unused_namespace_dict = {}
    for attr in context:
        n = attr.nodeName
        if n in unsuppressedPrefixes:
            inclusive.append(attr)
        elif n.startswith('xmlns:') and n[6:] in unsuppressedPrefixes:
            inclusive.append(attr)
        elif n.startswith('xmlns') and n[5:] in unsuppressedPrefixes:
            inclusive.append(attr)
        elif attr.nodeName in usedPrefixes:
            inclusive.append(attr)
        elif n.startswith('xmlns:'):
            unused_namespace_dict[n] = attr.value

    return inclusive, unused_namespace_dict
339294
protected function loadNamespaces(){
        $namespaces = [];
        foreach($this->queryXPath('namespace::*') as $node){
            $name = preg_replace('/xmlns(:)?/', '', $node->nodeName);
            if($name !== 'xml'){//always removed the implicit xml namespace
                $namespaces[$name] = $node->nodeValue;
            }
        }
        ksort($namespaces);
        foreach($namespaces as $name => $uri){
            $this->item->addNamespace($name, $uri);
        }
    }
454221
def namespaces(*prefixes):
    
    namespaces = {}
    for prefix in prefixes:
        namespaces[prefix] = _nsmap[prefix]
    return namespaces