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


C# XDocument.XPathEvaluate方法代码示例

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


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

示例1: 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

示例2: GetSingleValuedStringFromXPath

        internal string GetSingleValuedStringFromXPath(XDocument document, string xpath)
        {
            if (document == null) { throw new ArgumentNullException("document"); }
            if (string.IsNullOrEmpty(xpath)) { throw new ArgumentNullException("xpath"); }

            IEnumerable attributes = document.XPathEvaluate(xpath) as IEnumerable;
            return attributes.Cast<XAttribute>().Single().Value;
        }
开发者ID:sayedihashimi,项目名称:khyber-pass,代码行数:8,代码来源:TestMSDeployHandler.cs

示例3: GetXmlDocumentation

 /// <summary>
 /// Returns the XML documentation (summary tag) for the specified member.
 /// </summary>
 /// <param name="member">The reflected member.</param>
 /// <param name="xml">XML documentation.</param>
 /// <returns>The contents of the summary tag for the member.</returns>
 public static string GetXmlDocumentation(this MemberInfo member, XDocument xml)
 {
     return xml.XPathEvaluate(
         String.Format(
             "string(/doc/members/member[@name='{0}']/summary)",
             GetMemberElementName(member)
         )
     ).ToString().Trim();
 }
开发者ID:gitter-badger,项目名称:nrobotremote,代码行数:15,代码来源:XmlDocumentationExtensions.cs

示例4: GetXmlDocumentation

        public static string GetXmlDocumentation(this TypedParameter parameter, XDocument xml)
        {
            if (xml == null) return String.Empty;

            return xml.XPathEvaluate(
                String.Format(
                    "string(/doc/members/member[@name='{0}']/param[@name='{1}'])",
                    GetMemberElementName(parameter.Function),
                    parameter.Name )
                ).ToString().Trim();
        }
开发者ID:algobasket,项目名称:Dynamo,代码行数:11,代码来源:XmlDocumentationExtensions.cs

示例5: GetSearchTags

        public static IEnumerable<string> GetSearchTags(this FunctionDescriptor member, XDocument xml)
        {
            if (xml == null) return new List<string>();

            return xml.XPathEvaluate(
                String.Format(
                    "string(/doc/members/member[@name='{0}']/search)",
                    GetMemberElementName(member)
                    )
                ).ToString().Split(',').Select(x => x.Trim()).Where(x => x != String.Empty);
        }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:11,代码来源:XmlDocumentationExtensions.cs

示例6: ValidatePath

 private string ValidatePath(XDocument document, XmlNamespaceManager xnm, string prefix)
 {
     try
     {
         var nsxpath = XPath.QualifyXPath(prefix);
         var check = ((IEnumerable)document.XPathEvaluate(nsxpath, xnm)).Cast<XObject>().FirstOrDefault();
         return check != null ? string.Empty : XPath;
     }
     catch (Exception ex)
     {
         return XPath + ": " + ex.Message;
     }
 }
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:13,代码来源:XPathValidator.cs

示例7: getWeatherJSON

        public string getWeatherJSON(string location)
        {
            string str = "";
            try
            {

                httpReq = (HttpWebRequest)WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + location + "&mode=xml"); //  starts a web request to an api hosted by openweathermap which returns an xml document with weather data
                response = (HttpWebResponse)httpReq.GetResponse(); // recieves the response
                readStream = response.GetResponseStream(); // the stream reader reads the response
                streamreader = new StreamReader(readStream, Encoding.UTF8); // sets it to a stream reader with the UTF8 encoding
                responseString = streamreader.ReadToEnd(); // reads ther esponse to a string
             

                XMLDoc = XDocument.Parse(responseString); // parses the recieved document into an object intended for working with xml documents


                IEnumerable att = (IEnumerable)XMLDoc.XPathEvaluate("/current/weather/@icon"); // the node we are interested in
               
                Console.WriteLine(att.Cast<XAttribute>().FirstOrDefault()); // debug info
                str = att.Cast<XAttribute>().FirstOrDefault().ToString(); // sets the string str to the found node

                string[] results = str.Split('"'); // splits it by the " character to get the data we are after split up

                return results[1];
                
            }
            catch (System.Net.WebException e) // if an exception was thrown, this will execute
            {

                return e.ToString();

            }
            //string responseWeather = returnIcon(responseString);



        }
开发者ID:henrybond158,项目名称:Holiday-App,代码行数:37,代码来源:HTTPIO.cs

示例8: PatchDtsIds

        private static XDocument PatchDtsIds(XDocument document)
        {
            var dtsIdDictionary = new Dictionary<string, string>();
            XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(new NameTable());
            xmlnsManager.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts");
            foreach (var dtsIdElement in document.XPathSelectElements("//DTS:Property[@DTS:Name='DTSID']", xmlnsManager))
            {
                XElement nameElement = dtsIdElement.Parent.XPathSelectElement("./DTS:Property[@DTS:Name='ObjectName']", xmlnsManager);
                if (nameElement != null)
                {
                    dtsIdDictionary.Add(dtsIdElement.Value, nameElement.Value);
                    dtsIdElement.Value = nameElement.Value;
                }
                else
                {
                    dtsIdElement.Value = "__GUID__";
                }
            }

            foreach (XAttribute refAttribute in (IEnumerable)document.XPathEvaluate("//@IDREF"))
            {
                refAttribute.Value = dtsIdDictionary[refAttribute.Value];
            }

            foreach (XElement connectionRef in (IEnumerable)document.XPathEvaluate("//DTS:Executable//DTS:ObjectData//ExecutePackageTask//Connection", xmlnsManager))
            {
                connectionRef.Value = dtsIdDictionary[connectionRef.Value];
            }

            foreach (XAttribute connectionRef in (IEnumerable)document.XPathEvaluate("//connection/@connectionManagerID"))
            {
                connectionRef.Value = dtsIdDictionary[connectionRef.Value];
            }

            return document;
        }
开发者ID:japj,项目名称:vulcan,代码行数:36,代码来源:DtsxComparer.cs

示例9: GetMemberElement

        private static string GetMemberElement(FunctionDescriptor function,
            string suffix, XDocument xml)
        {
            // Construct the entire function descriptor name, including CLR style names
            string clrMemberName = GetMemberElementName(function);

            // match clr member name
            var match = xml.XPathEvaluate(
                String.Format("string(/doc/members/member[@name='{0}']/{1})", clrMemberName, suffix));

            if (match is String && !string.IsNullOrEmpty((string)match))
            {
                return match as string;
            }

            // fallback, namespace qualified method name
            var methodName = function.QualifiedName;

            // match with fallback
            match = xml.XPathEvaluate(
                String.Format(
                    "string(/doc/members/member[contains(@name,'{0}')]/{1})", methodName, suffix));

            if (match is String && !string.IsNullOrEmpty((string)match))
            {
                return match as string;
            }

            return String.Empty;
        }
开发者ID:RobertiF,项目名称:Dynamo,代码行数:30,代码来源:XmlDocumentationExtensions.cs

示例10: PrepareTemplate

        protected virtual ParsedTemplate PrepareTemplate(TemplateData templateData)
        {
            // clone orig doc
            XDocument workingDoc = new XDocument(this._templateDefinition);

            // start by loading any parameters as they are needed for meta-template evaluation

            Dictionary<string, XPathVariable> globalParams = new Dictionary<string, XPathVariable>();

            XElement[] paramNodes = workingDoc.Root.Elements("parameter").ToArray();
            foreach (XElement paramNode in paramNodes)
            {
                var tmplVar = new XPathVariable
                                  {
                                      Name = paramNode.Attribute("name").Value,
                                      ValueExpression =
                                          paramNode.Attribute("select") == null
                                              ? null
                                              : paramNode.Attribute("select").Value,
                                  };
                globalParams.Add(tmplVar.Name, tmplVar);
            }


            CustomXsltContext customContext = new CustomXsltContext();
            Func<string, object> onFailedResolve =
                s =>
                {
                    throw new InvalidOperationException(
                        String.Format("Parameter '{0}' could not be resolved.", s));
                };

            customContext.OnResolveVariable +=
                s =>
                {
                    XPathVariable var;

                    // if it's defined
                    if (globalParams.TryGetValue(s, out var))
                    {
                        // see if the user provided a value
                        object value;
                        if (templateData.Arguments.TryGetValue(s, out value))
                            return value;

                        // evaluate default value
                        if (!String.IsNullOrWhiteSpace(var.ValueExpression))
                            return workingDoc.XPathEvaluate(var.ValueExpression,
                                                            customContext);
                    }

                    return onFailedResolve(s);
                };

            // check for meta-template directives and expand
            XElement metaNode = workingDoc.Root.Elements("meta-template").FirstOrDefault();

            // we're going to need this later
            XmlFileProviderResolver fileResolver = new XmlFileProviderResolver(this._fileProvider, this._basePath);

            while (metaNode != null)
            {
                if (EvalCondition(customContext, metaNode, this.GetAttributeValueOrDefault(metaNode, "condition")))
                {
                    #region Debug conditional

#if DEBUG
                    const bool debugEnabled = true;
#else
                    const bool debugEnabled = false;
#endif

                    #endregion

                    XslCompiledTransform metaTransform = this.LoadStylesheet(metaNode.Attribute("stylesheet").Value);

                    XsltArgumentList xsltArgList = new XsltArgumentList();

                    // TODO this is a quick fix/hack
                    xsltArgList.AddExtensionObject("urn:lostdoc-core", new TemplateXsltExtensions(null, null));

                    var metaParamNodes = metaNode.Elements("with-param");

                    foreach (XElement paramNode in metaParamNodes)
                    {
                        string pName = paramNode.Attribute("name").Value;
                        string pExpr = paramNode.Attribute("select").Value;

                        xsltArgList.AddParam(pName,
                                             string.Empty,
                                             workingDoc.XPathEvaluate(pExpr, customContext));
                    }

                    XDocument outputDoc = new XDocument();
                    using (XmlWriter outputWriter = outputDoc.CreateWriter())
                    {
                        metaTransform.Transform(workingDoc.CreateNavigator(),
                                                xsltArgList,
                                                outputWriter,
                                                fileResolver);
//.........这里部分代码省略.........
开发者ID:LBi-Dick,项目名称:LBi.LostDoc,代码行数:101,代码来源:Template.cs

示例11: XPathCount

 private static int XPathCount(XDocument output, string path)
 {
     return Convert.ToInt32(output.XPathEvaluate(String.Format("count({0})", path)));
 }
开发者ID:RichardSlater,项目名称:NitriqTeamCity,代码行数:4,代码来源:WhenTestingTeamCityInfoXmlGenerator.cs

示例12: XPathIsValid

        private bool XPathIsValid(XDocument doc, XElement element, string xPath)
        {
            var xPathEvaluate = doc.XPathEvaluate(xPath);
            var xPathResults = doc.XPathSelectElements(xPath).ToArray();

            var result = (xPathResults.Count() == 1 &&
                xPathResults.First().ToString() == element.ToString());

            return result;
        }
开发者ID:TA-Gen,项目名称:TA-Gen,代码行数:10,代码来源:XPathFinder.cs

示例13: GetTargetImportNode

        private static XElement GetTargetImportNode(XDocument document)
        {
            var namespaceManager = new XmlNamespaceManager(new NameTable());
            namespaceManager.AddNamespace("aw", "http://schemas.microsoft.com/developer/msbuild/2003");

            var importProjectNode =
                (IEnumerable)
                    document.XPathEvaluate("/aw:Project/aw:Import[@Project='BridgeBuildTask.targets']",
                        namespaceManager);


            var linqBridgeTargetImportNode = importProjectNode.Cast<XElement>().FirstOrDefault();

            return linqBridgeTargetImportNode;
        }
开发者ID:vebin,项目名称:LINQBridgeVs,代码行数:15,代码来源:PackageConfigurator.cs

示例14: XPathExists

 private static bool XPathExists(XDocument output, string path)
 {
     return Convert.ToBoolean(output.XPathEvaluate(String.Format("boolean({0})", path)));
 }
开发者ID:RichardSlater,项目名称:NitriqTeamCity,代码行数:4,代码来源:WhenTestingTeamCityInfoXmlGenerator.cs

示例15: GetTestProvider

		private static string GetTestProvider(XDocument file)
		{
			return file.XPathEvaluate("string(/configuration/specFlow/unitTestProvider/@name)") as string;
		}
开发者ID:stajs,项目名称:SpecFlow.Dnx,代码行数:4,代码来源:AppConfig.cs


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