System.Xml.XmlNamespaceManager.LookupPrefix C# (CSharp) Méthode

LookupPrefix() public méthode

public LookupPrefix ( string uri ) : string
uri string
Résultat string
        public virtual string LookupPrefix( string uri ) {
            // Don't assume that prefix is atomized
            for( int thisDecl = lastDecl; thisDecl >= 0; thisDecl -- ) {
                if ( String.Equals( nsdecls[thisDecl].uri, uri ) ) {
                    string prefix = nsdecls[thisDecl].prefix;
                    if ( String.Equals( LookupNamespace( prefix ), uri ) ) {
                        return prefix;
                    }
                }
            }
            return null;
        }

Usage Example

Exemple #1
0
        public static void PerformQTConfigPatches(string devenvroot, string agentExecutable, string subpath, IDictionary<Assembly, KeyValuePair<bool, bool?>> actions)
        {
            var agentConfigFile = Path.Combine(devenvroot, agentExecutable + ".config");
            string ns = "urn:schemas-microsoft-com:asm.v1";

            var x = new XmlDocument();
            x.Load(agentConfigFile);
            var nsm = new XmlNamespaceManager(x.NameTable);
            var prf = nsm.LookupPrefix(ns);
            if (string.IsNullOrEmpty(prf)) nsm.AddNamespace(prf = "asm1", ns);

            bool changed = false;
            foreach (var pair in actions)
            {
                var asm = pair.Key;
                var cleanup = pair.Value.Key;
                var newstate = pair.Value.Value;
                var filepath = Path.Combine(subpath, Path.GetFileName(asm.Location));

                if (cleanup) changed |= junkRemover(x, asm.GetName(), ns, prf, nsm);

                if (newstate == true) changed |= exactWriter(x, filepath, asm.GetName(), ns, prf, nsm);
                else if (newstate == false) changed |= exactRemover(x, filepath, asm.GetName(), ns, prf, nsm);
            }

            if (changed)
                x.Save(agentConfigFile);
        }
All Usage Examples Of System.Xml.XmlNamespaceManager::LookupPrefix