public string RegisterNamespace(string namespaceUri, string suggestedPrefix) { ParameterAsserts.AssertSchemaNs(namespaceUri); ParameterAsserts.AssertPrefix(suggestedPrefix); if (suggestedPrefix[suggestedPrefix.Length - 1] != ':') { suggestedPrefix += ':'; } if (!Utils.IsXmlNameNs(suggestedPrefix.Substring(0, suggestedPrefix.Length - 1))) { throw new XmpException("The prefix is a bad XML name", XmpError.BADXML); } string registeredPrefix = (string)_namespaceToPrefixMap[namespaceUri]; string registeredNs = (string)_prefixToNamespaceMap[suggestedPrefix]; if (registeredPrefix != null) { // Return the actual prefix return(registeredPrefix); } if (registeredNs != null) { // the namespace is new, but the prefix is already engaged, // we generate a new prefix out of the suggested string generatedPrefix = suggestedPrefix; for (int i = 1; _prefixToNamespaceMap.Contains(generatedPrefix); i++) { generatedPrefix = suggestedPrefix.Substring(0, suggestedPrefix.Length - 1) + "_" + i + "_:"; } suggestedPrefix = generatedPrefix; } _prefixToNamespaceMap[suggestedPrefix] = namespaceUri; _namespaceToPrefixMap[namespaceUri] = suggestedPrefix; // Return the suggested prefix return(suggestedPrefix); }