当前位置: 首页>>代码示例>>C#>>正文


C# XNode.XPathSelectElements方法代码示例

本文整理汇总了C#中XNode.XPathSelectElements方法的典型用法代码示例。如果您正苦于以下问题:C# XNode.XPathSelectElements方法的具体用法?C# XNode.XPathSelectElements怎么用?C# XNode.XPathSelectElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XNode的用法示例。


在下文中一共展示了XNode.XPathSelectElements方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReplaceAppSettingOrConnectionString

        static IEnumerable<string> ReplaceAppSettingOrConnectionString(XNode document, string xpath, string keyAttributeName, string keyAttributeValue, string valueAttributeName, VariableDictionary variables)
        {
            var changes = new List<string>();
            var settings = (
                from element in document.XPathSelectElements(xpath)
                let keyAttribute = element.Attribute(keyAttributeName)
                where keyAttribute != null
                where string.Equals(keyAttribute.Value, keyAttributeValue, StringComparison.InvariantCultureIgnoreCase)
                select element).ToList();

            if (settings.Count == 0)
                return changes;

            var value = variables.Get(keyAttributeValue) ?? string.Empty;

            foreach (var setting in settings)
            {
                changes.Add(string.Format("Setting '{0}' = '{1}'", keyAttributeValue, value));

                var valueAttribute = setting.Attribute(valueAttributeName);
                if (valueAttribute == null)
                {
                    setting.Add(new XAttribute(valueAttributeName, value));
                }
                else
                {
                    valueAttribute.SetValue(value);
                }
            }

            return changes;
        }
开发者ID:merbla,项目名称:Calamari,代码行数:32,代码来源:ConfigurationVariablesReplacer.cs

示例2: SelectWithRootNamespace

 static IEnumerable<XElement> SelectWithRootNamespace(XNode container, string namespaceName, IEnumerable<Traversal> traversals)
 {
     var nav = container.CreateNavigator();
     var xPath = traversals.ToXPath("x");
     var manager = new XmlNamespaceManager(nav.NameTable);
     manager.AddNamespace("x", namespaceName);
     return container.XPathSelectElements(xPath, manager);
 }
开发者ID:joshski,项目名称:neffigy,代码行数:8,代码来源:XContainerExtensions.cs

示例3: LoadModules

 private void LoadModules(XNode configRoot)
 {
     var elements = configRoot.XPathSelectElements("modules/module");
     _moduleInstancesInstances = new List<ModuleInstance>(elements.Count());
     elements.ForEachItem(m =>
     {
         var type = m.Attribute("Type").Value;
         var active = m.Attribute("Active")?.Value.ToBoolean() ?? true;
         _moduleInstancesInstances.Add(new ModuleInstance(type, active));
     });
 }
开发者ID:saturn72,项目名称:Saturn72.Core,代码行数:11,代码来源:XmlConfigManager.cs

示例4: ReadUpdates

        private UpdatesMetadata[] ReadUpdates(XNode xNode)
        {
            var runners = new List<UpdatesMetadata>();
            // Add all sql runners
            foreach (var sqlRunnerXMl in xNode.XPathSelectElements("sqlRunner")){
                var command = sqlRunnerXMl.Element("command");
                var rollback = sqlRunnerXMl.Element("rollback");
                var testData = sqlRunnerXMl.Element("testData");
                var runner = new SqlRunner(GetSqlElement(command),
                                           GetSqlElement(rollback),
                                           GetSqlElement(testData));

                var versions = new UpdatesMetadata(
                    Convert.ToInt32(ReadAttribute(sqlRunnerXMl, "index")),
                    ReadAttribute(sqlRunnerXMl, "createDate"),
                    ReadAttribute(sqlRunnerXMl, "description"),
                    ReadAttribute(sqlRunnerXMl, "createBy"), runner)
                    {
                        SkipTransaction = Convert.ToBoolean(ReadAttribute(sqlRunnerXMl, "skipTransaction") ?? "False")
                    };
                runners.Add(versions);
            }

            return runners.ToArray();
        }
开发者ID:rolfwessels,项目名称:databaseversioncontrol,代码行数:25,代码来源:XmlConfigFileLoader.cs

示例5: ResolveCrefLink

        private void ResolveCrefLink(XNode node, string nodeSelector, Action<string, string> addReference)
        {
            if (node == null || string.IsNullOrEmpty(nodeSelector)) return;

            try
            {
                var nodes = node.XPathSelectElements(nodeSelector + "[@cref]").ToList();
                foreach (var item in nodes)
                {
                    var cref = item.Attribute("cref").Value;
                    // Strict check is needed as value could be an invalid href, 
                    // e.g. !:Dictionary&lt;TKey, string&gt; when user manually changed the intellisensed generic type
                    if (CommentIdRegex.IsMatch(cref))
                    {
                        var value = cref.Substring(2);

                        // When see and seealso are top level nodes in triple slash comments, do not convert it into xref node
                        if (item.Parent?.Parent != null)
                        {
                            var replacement = XElement.Parse($"<xref href=\"{HttpUtility.UrlEncode(value)}\" data-throw-if-not-resolved=\"false\"></xref>");
                            item.ReplaceWith(replacement);
                        }

                        if (addReference != null)
                        {
                            addReference(value, cref);
                        }
                    }
                    else
                    {
                        var detailedInfo = new StringBuilder();
                        if (_context != null && _context.Source != null)
                        {
                            if (!string.IsNullOrEmpty(_context.Source.Name))
                            {
                                detailedInfo.Append(" for ");
                                detailedInfo.Append(_context.Source.Name);
                            }
                            if (!string.IsNullOrEmpty(_context.Source.Path))
                            {
                                detailedInfo.Append(" defined in ");
                                detailedInfo.Append(_context.Source.Path);
                                detailedInfo.Append(" Line ");
                                detailedInfo.Append(_context.Source.StartLine);
                            }
                        }

                        Logger.Log(LogLevel.Warning, $"Invalid cref value \"{cref}\" found in triple-slash-comments{detailedInfo}, ignored.");
                    }
                }
            }
            catch
            {
            }
        }
开发者ID:dotnet,项目名称:docfx,代码行数:55,代码来源:TripleSlashCommentModel.cs

示例6: populateSenderAndReceiver

        void populateSenderAndReceiver( XNode node )
        {
            SendersEmailDisplayName = valueOrEmpty( node, @"Settings/Sender/DisplayName" ) ;
            SendersEmailAddress = valueOrEmpty(node,@"Settings/Sender/EmailAddress");

            _recipients.AddRange(
                new List< string >( from XElement e in node.XPathSelectElements( @"Settings/Recipients/Recipient" )
                select e.Value ) ) ;
        }
开发者ID:nomailme,项目名称:treetrim,代码行数:9,代码来源:StaticSettings.cs

示例7: populateAnyAdditionalAttachments

 void populateAnyAdditionalAttachments( XNode document )
 {
     _attachments.AddRange( new List< string >(
                            from XElement a in document.XPathSelectElements(
                                @"Settings/AdditionalAttachments/Attachment" )
                            select a.Value
                        ) ) ;
 }
开发者ID:nomailme,项目名称:treetrim,代码行数:8,代码来源:StaticSettings.cs

示例8: RecreateContentSources

        private void RecreateContentSources(XNode config, SPServiceContext context)
        {
            // Get the search service application proxy
            var searchProxy = SearchServiceApplicationProxy.GetProxy(context);

            if (searchProxy == null)
                throw new Exception(DefaultSsaProxyNotFoundExceptionMessage);

            var ssaInfo = searchProxy.GetSearchServiceApplicationInfo();
            var searchApp = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssaInfo.SearchServiceApplicationId);
            var content = new Content(searchApp);

            // Remove content sources specified by remove tag in configuration XML.
            var removeContentSourceElements = config.XPathSelectElements("/SearchConfiguration/ContentSources/remove");
            foreach (var removeContentSourceElement in removeContentSourceElements)
            {
                var contentSourceName = TryGetAttributeValue(removeContentSourceElement, "Name");
                if (content.ContentSources.Exists(contentSourceName))
                {
                    var contentSource = content.ContentSources[contentSourceName];
                    contentSource.Delete();
                }
                else
                {
                    Logger.LogMessage(
                        SeverityLevels.Warning,
                        LogCategory,
                        string.Format(ContentSourceNotFoundRemovalFailedLogFormat,
                            contentSourceName));
                }
            }

            // Create new Content Sources (if they don't exist)
            var contentSourceElements = config.XPathSelectElements("/SearchConfiguration/ContentSources/ContentSource");
            foreach (var contentSourceElement in contentSourceElements)
            {
                var contentSourceName = TryGetAttributeValue(contentSourceElement,"Name");
                var contentSourceExists = content.ContentSources.Exists(contentSourceName);
                if (contentSourceExists)
                {
                    Logger.LogMessage(
                        SeverityLevels.Information,
                        LogCategory,
                        string.Format(ContentSourceExistsLogFormat,
                            contentSourceName));
                    var recreateAttr = contentSourceElement.Attribute("RecreateIfExists");
                    if (recreateAttr != null && bool.Parse(recreateAttr.Value))
                    {
                        var contentSource = content.ContentSources[contentSourceName];
                        if (contentSource.StartAddresses.Count > 0)
                        {
                            contentSource.StartAddresses.Clear();
                            contentSource.Update();
                        }
                        contentSource.Delete();
                        contentSourceExists = false;
                    }
                }
                if (!contentSourceExists)
                {
                    var contentSourceTypeName = TryGetAttributeValue(contentSourceElement,"Type");
                    var startFullCrawl = bool.Parse(contentSourceElement.AttributeOrDefault("StartFullCrawl", "false"));
                    var contentSourceType = GetContentSourceTypeFromString(contentSourceTypeName);
                    var contentSource = content.ContentSources.Create(contentSourceType, contentSourceName);
                    ConstructStartAddresses(contentSource, contentSourceElement.Elements("StartAddress"));
                    contentSource.Update();
                    if (startFullCrawl)
                        contentSource.StartFullCrawl();
                }
            }
        }
开发者ID:rezanid,项目名称:SPContribute,代码行数:71,代码来源:SearchAdminUtility.cs

示例9: RebuildMetadataProperties

        private static void RebuildMetadataProperties(XNode config, SPServiceContext context)
        {
            // Get the search service application proxy
            var searchProxy = SearchServiceApplicationProxy.GetProxy(context);
            // Another alternative is the following line ;)
            // * var searchProxy =
            //   context.GetDefaultProxy(typeof (SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;

            if (searchProxy == null)
                throw new InvalidOperationException("Search Service Application was not found.");

            // Get the search service application info object so we can find the Id of
            // our Search Service Application.
            var ssai = searchProxy.GetSearchServiceApplicationInfo();

            // Get the application itself
            var searchApp = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssai.SearchServiceApplicationId);

            // Get the schema of our Search Service Application
            var schema = new Schema(searchApp);

            var crawledPropsCache = new List<CrawledProperty>();
            var categories = schema.AllCategories;

            // Remove Managed Properties
            var managedPropsRemove = config.XPathSelectElements("/SearchConfiguration/ManagedProperties/remove");
            RemoveManagedProperties(schema, managedPropsRemove);

            var loadedCategories = new HashSet<string>();

            // Add / update crawled properties under different categories
            // SearchConfiguration > CrawledProperties > Category
            foreach (var categoryCfg in config.XPathSelectElements("/SearchConfiguration/CrawledProperties/Category"))
            {
                // If crawled properties in this category are not loaded
                // load them and add category name to the list.
                var categoryName = TryGetAttributeValue(categoryCfg, "Name");
                if (string.IsNullOrEmpty(categoryName))
                {
                    Logger.LogMessage(SeverityLevels.Critical, LogCategory,
                        string.Format(CategoryAttributeMissingLogFormat, "Name"));
                    continue;
                }
                var cat = categories[categoryName];
                if (!loadedCategories.Contains(categoryName))
                {
                    crawledPropsCache.AddRange(categories[categoryName].GetAllCrawledProperties().Cast<CrawledProperty>());
                    loadedCategories.Add(categoryName);
                }

                // SearchConfiguration > CrawledProperties > Category > * (clear | CrawledProperty)
                foreach (var crawledPropCfg in categoryCfg.Elements())
                {
                    if (crawledPropCfg.Name == "clear")
                    {
                        ClearCrawledPropertiesInCategory(crawledPropsCache, cat, categoryCfg);
                    }
                    else if (crawledPropCfg.Name == "CrawledProperty")
                    {
                        // Create the crawled property if it doesn't exist
                        CreateCrawledPropertyIfDoesNotExist(crawledPropsCache, cat, crawledPropCfg);
                    }
                }

            }
            // Get all the managed properties
            // Create all required managed properties
            // SearchConfiguration > ManagedProperties > ManagedProperty
            // foreach (var managedPropCfg in config.Element("SearchConfiguration").Element("ManagedProperties").Elements("ManagedProperty"))
            foreach (var managedPropCfg in config.XPathSelectElements("/SearchConfiguration/ManagedProperties/ManagedProperty"))
            {
                var managedPropName = TryGetAttributeValue(managedPropCfg, "Name");
                if (string.IsNullOrEmpty(managedPropName))
                {
                    Logger.LogMessage(SeverityLevels.Critical, LogCategory,
                        string.Format(UnknownManagedPropertyAttributeMissingLogFormat, "Name"));
                    continue;
                }
                var managedPropType = TryGetAttributeValue(managedPropCfg, "Type");
                if (string.IsNullOrEmpty(managedPropType))
                {
                    Logger.LogMessage(SeverityLevels.Critical, LogCategory,
                        string.Format(KnownManagedPropertyAttributeMissingLogFormat, managedPropName, "Type"));
                    continue;
                }
                var managedProp = CreateOrGetManagedProperty(schema, managedPropName, managedPropType);

                // Create all the required mappings for the current Managed Property
                var isMappingChanged = false;
                MappingCollection mappings = null;
                foreach (var mapCfg in managedPropCfg.Elements())
                {
                    if (mapCfg.Name == "clear")
                    {
                        // Clear all mappings of this ManagedProperty
                        managedProp.DeleteAllMappings();
                        isMappingChanged = true;
                    }
                    else if (mapCfg.Name == "Map")
                    {
//.........这里部分代码省略.........
开发者ID:rezanid,项目名称:SPContribute,代码行数:101,代码来源:SearchAdminUtility.cs


注:本文中的XNode.XPathSelectElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。