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


C# XDocument.XPathSelectElement方法代码示例

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


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

示例1: ModifyConfig

        public override void ModifyConfig(XDocument doc)
        {
            const string Instructions = @"<MessageForwardingInCaseOfFaultConfig 
    ErrorQueue=""The queue to which errors will be forwarded."" />";

            var sectionElement = doc.XPathSelectElement("/configuration/configSections/section[@name='MessageForwardingInCaseOfFaultConfig' and @type='NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core']");
            if (sectionElement == null)
            {

                doc.XPathSelectElement("/configuration/configSections").Add(new XElement("section",
                                                                                         new XAttribute("name",
                                                                                                        "MessageForwardingInCaseOfFaultConfig"),
                                                                                         new XAttribute("type",
                                                                                                        "NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core")));

            }

            var forwardingElement = doc.XPathSelectElement("/configuration/MessageForwardingInCaseOfFaultConfig");
            if (forwardingElement == null)
            {
                doc.Root.LastNode.AddAfterSelf(new XComment(Instructions), 
                                                new XElement("MessageForwardingInCaseOfFaultConfig",
                                                new XAttribute("ErrorQueue", "error")));
            }
        }
开发者ID:89sos98,项目名称:NServiceBus,代码行数:25,代码来源:AddMessageForwardingInCaseOfFaultConfig.cs

示例2: addElements

 private void addElements (XDocument manifest, params string[] elements) {
     foreach (var element in elements) {
         if (null == manifest.XPathSelectElement(element, this)) {
             manifest.XPathSelectElement(getParentElement(element), this).Add(getElement(element));
         }
     }
 }
开发者ID:nhhoang,项目名称:shooting,代码行数:7,代码来源:AndroidManifestMerger.cs

示例3: DrawRegistryDocument

        public string DrawRegistryDocument(XDocument xd)
        {
            string sHTML = "";
            if (xd.XPathSelectElement("registry") != null)
            {
                sHTML += "<div class=\"ui-widget-content ui-corner-bottom registry\">";
                sHTML += "  <div class=\"ui-state-default registry_section_header\" xpath=\"registry\">"; //header
                sHTML += "      <div class=\"registry_section_header_title\">Registry</div>";

                sHTML += "<div class=\"registry_section_header_icons\">"; //step header icons

                sHTML += "<span id=\"registry_refresh_btn\" class=\"pointer\">" +
                    "<img style=\"width:10px; height:10px;\" src=\"../images/icons/reload_16.png\"" +
                    " alt=\"\" title=\"Refresh\" /></span>";

                sHTML += "<span class=\"registry_node_add_btn pointer\"" +
                    " xpath=\"registry\">" +
                    "<img style=\"width:10px; height:10px;\" src=\"../images/icons/edit_add.png\"" +
                    " alt=\"\" title=\"Add another...\" /></span>";

                sHTML += "</div>";  //end step header icons
                sHTML += "  </div>"; //end header

                foreach (XElement xe in xd.XPathSelectElement("registry").Nodes())
                {
                    sHTML += DrawRegistryNode(xe, "registry/" + xe.Name.ToString());
                }

                sHTML += "</div>";
            }

            if (sHTML.Length == 0)
                sHTML = "Registry is empty.";
            return sHTML;
        }
开发者ID:remotesyssupport,项目名称:cato,代码行数:35,代码来源:uiMethods.asmx.cs

示例4: ModifyConfig

        public override void ModifyConfig(XDocument doc)
        {
            // Add the new audit config section, if the ForwardReceivedMessagesTo attribute has not been set in the UnicastBusConfig.
            var frmAttributeEnumerator = (IEnumerable)doc.XPathEvaluate("/configuration/UnicastBusConfig/@ForwardReceivedMessagesTo");
            var isForwardReceivedMessagesAttributeDefined = frmAttributeEnumerator.Cast<XAttribute>().Any();

            // Then add the audit config
            var sectionElement =
                doc.XPathSelectElement(
                    "/configuration/configSections/section[@name='AuditConfig' and @type='NServiceBus.Config.AuditConfig, NServiceBus.Core']");
            if (sectionElement == null)
            {
                if (isForwardReceivedMessagesAttributeDefined)
                    doc.XPathSelectElement("/configuration/configSections").Add(new XComment(exampleAuditConfigSection));
                else
                    doc.XPathSelectElement("/configuration/configSections").Add(new XElement("section",
                    new XAttribute("name",
                        "AuditConfig"),
                    new XAttribute("type",
                        "NServiceBus.Config.AuditConfig, NServiceBus.Core")));
            }

            var forwardingElement = doc.XPathSelectElement("/configuration/AuditConfig");
            if (forwardingElement == null)
            {
                doc.Root.LastNode.AddAfterSelf(new XComment(Instructions),
                    isForwardReceivedMessagesAttributeDefined ? (object) new XComment(@"Since we detected that you already have forwarding setup we haven't enabled the audit feature.
Please remove the ForwardReceivedMessagesTo attribute from the UnicastBusConfig and uncomment the AuditConfig section. 
<AuditConfig QueueName=""audit"" />") : new XElement("AuditConfig", new XAttribute("QueueName", "audit")));
            }

        }
开发者ID:89sos98,项目名称:NServiceBus,代码行数:32,代码来源:AddAuditConfig.cs

示例5: Save

		public static void Save(BlogPost post, string file) {
			post.LastModified = DateTime.UtcNow;

			XDocument doc = new XDocument(
				new XElement("post",
					new XElement("title", post.Title),
					new XElement("slug", post.Slug),
					new XElement("author", post.Author),
					new XElement("pubDate", post.PubDate.ToString("yyyy-MM-dd HH:mm:ss")),
					new XElement("lastModified", post.LastModified.ToString("yyyy-MM-dd HH:mm:ss")),
					new XElement("content", post.Content),
					new XElement("ispublished", post.IsPublished),
					new XElement("categories", string.Empty),
					new XElement("comments", string.Empty)
					));

			XElement categories = doc.XPathSelectElement("post/categories");
			foreach (string category in post.Categories) {
				categories.Add(new XElement("category", category));
			}

			XElement comments = doc.XPathSelectElement("post/comments");

			doc.Save(file);
		}
开发者ID:Jandev,项目名称:JanVNL.Migrate,代码行数:25,代码来源:Storage.cs

示例6: InsertJob

        public static void InsertJob(XDocument jobXml)
        {
            string username = jobXml.XPathSelectElement("data/username").Value;

            Console.WriteLine("Username: {0}", username);
            Console.WriteLine("Job type: {0}", jobXml.XPathSelectElement("data/").Value);
        }
开发者ID:edujso,项目名称:JobReportGenerator,代码行数:7,代码来源:Program.cs

示例7: GetProjectOutputMode

        public OutputPathMode GetProjectOutputMode(XDocument document)
        {
            var platformSpecificOutputFolderElement = document.XPathSelectElement("/Project/Properties/PlatformSpecificOutputFolder");
            var projectSpecificOutputFolderElement = document.XPathSelectElement("/Project/Properties/ProjectSpecificOutputFolder");
            var platformSpecificOutputFolder = true;
            var projectSpecificOutputFolder = false;

            if (platformSpecificOutputFolderElement != null)
            {
                platformSpecificOutputFolder = platformSpecificOutputFolderElement.Value.ToLowerInvariant() != "false";
            }
            if (projectSpecificOutputFolderElement != null)
            {
                projectSpecificOutputFolder = projectSpecificOutputFolderElement.Value.ToLowerInvariant() == "true";
            }

            var outputMode = OutputPathMode.BinConfiguration;
            if (projectSpecificOutputFolder)
            {
                outputMode = OutputPathMode.BinProjectPlatformArchConfiguration;
            }
            if (platformSpecificOutputFolder)
            {
                outputMode = OutputPathMode.BinPlatformArchConfiguration;
            }

            return outputMode;
        }
开发者ID:marler8997,项目名称:Protobuild,代码行数:28,代码来源:ProjectOutputPathCalculator.cs

示例8: Save

    // Can this be done async?
    public static void Save(Post post)
    {
        string file = Path.Combine(_folder, post.ID + ".xml");
        post.LastModified = DateTime.UtcNow;

        XDocument doc = new XDocument(
                        new XElement("post",
                            new XElement("title", post.Title),
                            new XElement("slug", post.Slug),
                            new XElement("author", post.Author),
                            new XElement("pubDate", post.PubDate.ToString("yyyy-MM-dd HH:mm:ss")),
                            new XElement("lastModified", post.LastModified.ToString("yyyy-MM-dd HH:mm:ss")),
                            new XElement("excerpt", post.Excerpt),
                            new XElement("content", post.Content),
                            new XElement("ispublished", post.IsPublished),
                            new XElement("categories", string.Empty),
                            new XElement("comments", string.Empty)
                        ));

        XElement categories = doc.XPathSelectElement("post/categories");
        foreach (string category in post.Categories)
        {
            categories.Add(new XElement("category", category));
        }

        XElement comments = doc.XPathSelectElement("post/comments");
        foreach (Comment comment in post.Comments)
        {
            comments.Add(
                new XElement("comment",
                    new XElement("author", comment.Author),
                    new XElement("email", comment.Email),
                    new XElement("website", comment.Website),
                    new XElement("ip", comment.Ip),
                    new XElement("userAgent", comment.UserAgent),
                    new XElement("date", comment.PubDate.ToString("yyyy-MM-dd HH:m:ss")),
                    new XElement("content", comment.Content),
                    new XAttribute("isAdmin", comment.IsAdmin),
                    new XAttribute("isApproved", comment.IsApproved),
                    new XAttribute("id", comment.ID)
                ));
        }

        if (!File.Exists(file)) // New post
        {
            var posts = GetAllPosts();
            posts.Insert(0, post);
            posts.Sort((p1, p2) => p2.PubDate.CompareTo(p1.PubDate));
            HttpRuntime.Cache.Insert("posts", posts);
        }
        else
        {
            Blog.ClearStartPageCache();
        }

        doc.Save(file);
    }
开发者ID:ampslive,项目名称:MiniBlog,代码行数:58,代码来源:Storage.cs

示例9: SimpleWriting

        private void SimpleWriting()
        {
            XDocument xd;
              XElement root;
              XElement child;

              xd =
            new XDocument(
              new XDeclaration("1.0", "utf-8", "yes"),
              new XComment("Employee Records"),
              new XElement("Employees"));

              root = xd.XPathSelectElement("//Employees");

              child = new XElement("Employee",
              new XElement("id", 1),
              new XElement("FirstName", "Bruce"),
              new XElement("LastName", "Jones"));

              root.Add(child);

              xd.Save(AppConfig.XmlFile);

              txtResult.Text = xd.ToString();
        }
开发者ID:ah16269,项目名称:rest-web-api-wcf,代码行数:25,代码来源:02-WriteXDocument.xaml.cs

示例10: Transform

 public virtual bool Transform(XDocument document)
 {
     if (document == null) { return false; }
     var element = document.XPathSelectElement(this.Xpath);
     if (element == null)
     {
         return false;
     }
     var attribute = element.Attribute(this.AttributeName);
     if (attribute == null)
     {
         return false;
     }
     var path = Path.Combine(this.FilePath, attribute.Value);
     if (!File.Exists(path))
     {
         throw new Exception(string.Format("Cannot find {0}", path));
     }
     var root = XDocument.Load(path).Root;
     if (!element.ToString().Equals(root.ToString()))
     {
         element.ReplaceWith(root);
         return true;
     }
     return false;
 }
开发者ID:adamconn,项目名称:sitecore-linqpad,代码行数:26,代码来源:MergeSettingsFromFileTransformer.cs

示例11: DesktopServiceConfiguration

        protected DesktopServiceConfiguration(string path, bool useRemoteConfig)
        {
            filePath = path;
            configDoc = XDocument.Load(path);
            XElement configXml = configDoc.XPathSelectElement("//selfServiceDesktops");
            if (configXml == null) {
                throw new ArgumentException("No <selfServiceDesktops/> configuration element found in : " + path);
            }
            config = Deserialize(configXml);

            if (useRemoteConfig && (config.RemoteConfig != null)) {
                try {
                    configXml = GetXml(new Uri(config.RemoteConfig));
                    string remoteConfig = config.RemoteConfig;
                    config = Deserialize(configXml);
                    // If the remote config does not have an agent URI, infer it from the remote Url in the local config
                    if (config.AgentUri == null) {
                        config.SetAgentUriFrom(remoteConfig);
                    }

                } catch (Exception e) {
                    throw new ConfigurationErrorsException("Unable to load configuration from remote server", e);
                }
            }
            ValidateConfiguration();
        }
开发者ID:siwater,项目名称:ssd_library,代码行数:26,代码来源:DesktopServiceConfiguration.cs

示例12: Main

        static void Main(string[] args)
        {
            var path = @"d:\1";

            var document = new XDocument(
                new XDeclaration("1.0", "UTF-8", null),
                new XElement("root-dir",
                    new XAttribute("path", path)));

            var files = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var fileDirectories = file.Replace(path, "")
                    .Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                var len = fileDirectories.Length;
                var root = document.Element("root-dir");
                XElement dir = root;

                for (int i = 0; i < len - 1; i++)
                {
                    dir = document.XPathSelectElement(String.Format("//dir[@name = '{0}']", fileDirectories[i]));
                    if (dir == null)
                    {
                        if (i < 1)
                        {
                            dir = root;
                        }
                        else
                        {
                            dir = document.XPathSelectElement(String.Format("//dir[@name = '{0}']", fileDirectories[i - 1]));
                        }

                        var newDir = new XElement("dir",
                            new XAttribute("name", fileDirectories[i]));
                        dir.Add(newDir);
                        dir = newDir;
                    }
                }

                dir.Add(new XElement("file",
                    new XAttribute("name", fileDirectories[len - 1])));
            }

            Console.WriteLine(document.Declaration);
            Console.WriteLine(document);
        }
开发者ID:Gleomit,项目名称:DB-Apps,代码行数:47,代码来源:XElementDirectoryContentsAsXML.cs

示例13: removeElements

 private void removeElements (XDocument manifest, params string[] elements) {
     foreach (var element in elements) {
         var e = manifest.XPathSelectElement(element, this);
         if (null != e) {
             e.Remove();
         }
     }
 }
开发者ID:nhhoang,项目名称:shooting,代码行数:8,代码来源:AndroidManifestMerger.cs

示例14: Parse

        /// <summary>
        /// Parses the results of a Core Status command.
        /// </summary>
        /// <param name="xml">The XML Document to parse.</param>
        /// <returns></returns>
        public List<CoreResult> Parse(XDocument xml) {
            var statusNode = xml.XPathSelectElement("response/lst[@name='status']");
            if (statusNode == null || !statusNode.HasElements)
                return new List<CoreResult>();

            var results = statusNode.Elements().Select(ParseCore).ToList();
            return results;
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:13,代码来源:SolrStatusResponseParser.cs

示例15: GetElementsToKeep

 private IList<XElement> GetElementsToKeep(XDocument copyDocument, string xpath)
 {
     var elementsToKeep = new List<XElement>();
     var element = copyDocument.XPathSelectElement(xpath, new SimpleXmlNamespaceResolver(copyDocument));
     elementsToKeep.AddRange(element.AncestorsAndSelf());
     elementsToKeep.AddRange(element.Descendants());
     return elementsToKeep;
 }
开发者ID:uli-weltersbach,项目名称:XPathInformation,代码行数:8,代码来源:XmlStructureWriter.cs


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