private string DeterminePrefixAndNamespaceUri() { if (!string.ReferenceEquals(namespaceUri, null)) { if (RootElement != null && namespaceUri.Equals(RootElement.NamespaceUri)) { // global namespaces do not have a prefix or namespace URI return(null); } else { // lookup for prefix string lookupPrefix = this.LookupPrefix(); if (string.ReferenceEquals(lookupPrefix, null) && RootElement != null) { // if no prefix is found we generate a new one // search for known prefixes string knownPrefix = KnownPrefixes[namespaceUri]; if (string.ReferenceEquals(knownPrefix, null)) { // generate namespace return(RootElement.RegisterNamespace(namespaceUri)); } else if (knownPrefix.Length == 0) { // ignored namespace return(null); } else { // register known prefix RootElement.RegisterNamespace(knownPrefix, namespaceUri); return(knownPrefix); } } else { return(lookupPrefix); } } } else { // no namespace so no prefix return(null); } }
public virtual void RegisterNamespace(string prefix, string namespaceUri) { lock (_document) { IDomElement rootElement = RootElement; if (rootElement != null) { rootElement.RegisterNamespace(prefix, namespaceUri); } else { throw new ModelException("Unable to define a new namespace without a root document element"); } } }