func (ns *Namespace) Resolve(uri string) (string, bool) {
	if ns == nil {
		return "", false
	}
	prefix, ok := ns.uriToPrefix[uri]
	return prefix, ok
}
Resolve resolves the given schema URI to its registered prefix and
returns the prefix and whether the resolution was successful.

If ns is nil, it is treated as if it were empty.

Resolve does not mutate ns and may be called concurrently
with other non-mutating Namespace methods.
package checkers
import (
	"sort"
	"strings"
	"unicode"
	"unicode/utf8"
	errgo "gopkg.in/errgo.v1"
)
type Namespace struct {
	uriToPrefix map[string]string
}
func NewNamespace(uriToPrefix map[string]string) *Namespace {
	ns := &Namespace{
		uriToPrefix: make(map[string]string),
	}
	for uri, prefix := range uriToPrefix {
		ns.Register(uri, prefix)
	}
	return ns
}
func (ns *Namespace) String() string {
	data, _ := ns.MarshalText()
	return string(data)
}
func (ns *Namespace) MarshalText() ([]byte, error) {
	if ns == nil || len(ns.uriToPrefix) == 0 {
		return nil, nil
	}
	uris := make([]string, 0, len(ns.uriToPrefix))
	dataLen := 0
	for uri, prefix := range ns.uriToPrefix {
		uris = append(uris, uri)
		dataLen += len(uri) + 1 + len(prefix) + 1
	}
	sort.Strings(uris)
	data := make([]byte, 0, dataLen)
	for i, uri := range uris {
		if i > 0 {
			data = append(data, ' ')
		}
		data = append(data, uri...)
		data = append(data, ':')
		data = append(data, ns.uriToPrefix[uri]...)
	}
	return data, nil
}
func (ns *Namespace) UnmarshalText(data []byte) error {
	uriToPrefix := make(map[string]string)
	elems := strings.Fields(string(data))
	for _, elem := range elems {
		i := strings.LastIndex(elem, ":")
		if i == -1 {
			return errgo.Newf("no colon in namespace field %q", elem)
		}
		uri, prefix := elem[0:i], elem[i+1:]
		if !IsValidSchemaURI(uri) {
			return errgo.Newf("invalid URI %q in namespace field %q", uri, elem)
		}
		if !IsValidPrefix(prefix) {
			return errgo.Newf("invalid prefix %q in namespace field %q", prefix, elem)
		}
		if _, ok := uriToPrefix[uri]; ok {
			return errgo.Newf("duplicate URI %q in namespace %q", uri, data)
		}
		uriToPrefix[uri] = prefix
	}
	ns.uriToPrefix = uriToPrefix
	return nil
}
func (ns *Namespace) EnsureResolved(uri string) (string, bool) {
	return ns.Resolve(uri)
}