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


C# XDocument.XPathSelectElements方法代码示例

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


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

示例1: TransformOutput

        public XDocument TransformOutput(XDocument output)
        {
            var elements = output.XPathSelectElements("//jetbrains.buildServer.messages.BuildMessage1"
                                                      + "[./myTypeId[text()='BlockStart'] and "
                                                      + ".//blockType[text() ='$TEST_BLOCK$']]");

            var tests = elements.Select(x => new TestResult 
            { 
                FullName = x.XPathSelectElement(".//blockName").Value, 
                RunTime = long.Parse(x.XPathSelectElement(".//myTimestamp").Value),
                Succeeded = x.NextNode.XPathSelectElement(".//myTypeId").Value != "TestFailure"
            })
            .OrderBy(x => x.RunTime);

            var testsToRemove = from testResult in tests.GroupBy(x => x.FullName)
                where testResult.Any(x => x.Succeeded)
                select testResult.Key;

            foreach (var testToRemove in testsToRemove)
            {
                output.XPathSelectElements(
                    "//jetbrains.buildServer.messages.BuildMessage1[./myTypeId[text()='TestFailure'] and .//testName[text()='"
                    + testToRemove + "']]").Remove();
            }

            return output;
        }
开发者ID:GavinWu,项目名称:NUnit-retry,代码行数:27,代码来源:RetryProxyExtension.cs

示例2: CreateDynamicContent

		// Creates the dynamic content from the twitter results
		RootElement CreateDynamicContent (XDocument doc)
		{
			var users = doc.XPathSelectElements ("./statuses/status/user").ToArray ();
			var texts = doc.XPathSelectElements ("./statuses/status/text").Select (x=>x.Value).ToArray ();
			var people = doc.XPathSelectElements ("./statuses/status/user/name").Select (x=>x.Value).ToArray ();
			
			var section = new Section ();
			var root = new RootElement ("Tweets") { section };
			
			for (int i = 0; i < people.Length; i++){
				var line = new RootElement (people [i]) { 
					new Section ("Profile"){
						new StringElement ("Screen name", users [i].XPathSelectElement ("./screen_name").Value),
						new StringElement ("Name", people [i]),
						new StringElement ("oFllowers:", users [i].XPathSelectElement ("./followers_count").Value)
					},
					new Section ("Tweet"){
						new StringElement (texts [i])
					}
				};
				section.Add (line);
			}
			
			return root;
		}
开发者ID:hisystems,项目名称:MonoTouch.Dialog,代码行数:26,代码来源:DemoDynamic.cs

示例3: GetContentByXPath

        private XDocument GetContentByXPath(string xpath, XDocument content)
        {
            var xdoc = XDocument.Parse("<content></content>");
            xdoc.Root.Add(content.XPathSelectElements(xpath));

            return xdoc;
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:7,代码来源:TestContentService.cs

示例4: Parse

        public static IBArchive Parse(XDocument xDoc)
        {
            IBArchive ibArchive = new IBArchive();

            foreach (XAttribute attr in xDoc.Root.Attributes())
            {
                if (attr.Name == "type")
                    ibArchive.Type = attr.Value;
                if (attr.Name == "version")
                    ibArchive.Version = attr.Value;
            }

            var elements = xDoc.XPathSelectElements(@"/archive/data/*");
            foreach (var element in elements)
            {
                var key = element.Attributes().Where(attr => attr.Name == "key").FirstOrDefault();
                if (key != null && element.Attribute("key").Value.StartsWith("IBDocument."))
                {
                    //IBDocument.Parse(ibArchive.Data, element);
                }
            }

            //if (xmlReader.Name == "archive")
            //{
            //    while (xmlReader.MoveToNextAttribute())
            //    {
            //        if (xmlReader.Name == "type")
            //            ibArchive.Type = xmlReader.Value;
            //        else if (xmlReader.Name == "version")
            //            ibArchive.Version = xmlReader.Value;
            //    }
            //}

            return ibArchive;
        }
开发者ID:smartmobili,项目名称:CocoaBuilder,代码行数:35,代码来源:IBArchive.cs

示例5: TraverseXmlDocument

 private static void TraverseXmlDocument(XDocument doc)
 {
     foreach (var leagueElement in doc.XPathSelectElements("leagues-and-teams/league"))
     {
         AddLeague(leagueElement);
     }
 }
开发者ID:StanislavBozhilov,项目名称:SoftwareUniversity,代码行数:7,代码来源:ImportLeaguesAndTeams.cs

示例6: Main

        static void Main()
        {
            string documentPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\expenses.xml";
            var xmlDocument = new XDocument();
            try
            {
                xmlDocument = XDocument.Load(documentPath);
                Console.WriteLine("XML file has been found!");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File not found!");
            }

            var nodes = xmlDocument.XPathSelectElements("//expenses-by-month/vendor");

            foreach (var vendor in nodes)
            {
                string vendorName = vendor.Attribute("name").Value;
                var expenses = vendor.Elements("expenses");

                foreach (var expense in expenses)
                {
                    DateTime month = DateTime.Parse(expense.Attribute("month").Value);
                    decimal amount = decimal.Parse(expense.Value);
                    AddVendorExpense(vendorName, month, amount);
                }
            }
        }
开发者ID:Team-Delphinium-Belladonna,项目名称:Project,代码行数:29,代码来源:LoadXML.cs

示例7: Transform

 public virtual bool Transform(XDocument document)
 {
     if (document == null) { return false; }
     var elementArray = document.XPathSelectElements(this.Xpath).ToArray<XElement>();
     if (elementArray.Length == 0) { return false; }
     var changeMade = false;
     foreach (var element in elementArray)
     {
         var attribute = element.Attribute(this.AttributeName);
         if (attribute == null) { continue; }
         string newValue = null;
         if (this.ChangeType == AttributeValueChangeType.Replace)
         {
             newValue = this.NewValue;
         }
         else if (this.ChangeType == AttributeValueChangeType.Prepend)
         {
             newValue = this.NewValue + attribute.Value;
         }
         else if (this.ChangeType == AttributeValueChangeType.Append)
         {
             newValue = attribute.Value + this.NewValue;
         }
         if (!string.IsNullOrEmpty(newValue) && ! newValue.Equals(attribute.Value))
         {
             attribute.Value = newValue;
             changeMade = true;
         }
     }
     return changeMade;
 }
开发者ID:adamconn,项目名称:sitecore-linqpad,代码行数:31,代码来源:AttributeValueTransformer.cs

示例8: ReportItems

        private static string ReportItems(XDocument xdoc, string path)
        {
            var sb = new StringBuilder();
            foreach (var e in xdoc.XPathSelectElements(path).Elements())
            {
                var roles = ((string)e.Attribute("roles"))?.Split(',');
                if (roles != null)
                    if (!roles.Any(rr => DbUtil.Db.CurrentUser.Roles.Contains(rr)))
                        continue;

                var tb = new TagBuilder("li");
                switch (e.Name.LocalName)
                {
                    case "Report":
                        var a = new TagBuilder("a");
                        a.MergeAttribute("href", e.Attribute("link").Value);
                        var t = e.Attribute("target");
                        if (t != null)
                            a.MergeAttribute("target", t.Value);
                        a.SetInnerText(e.Value);
                        tb.InnerHtml = a.ToString();
                        break;
                    case "Header":
                        tb.AddCssClass("dropdown-header");
                        tb.SetInnerText(e.Value);
                        break;
                    case "Space":
                        tb.AddCssClass("divider");
                        break;
                }
                sb.AppendLine(tb.ToString());
            }
            return sb.ToString();
        }
开发者ID:stevesloka,项目名称:bvcms,代码行数:34,代码来源:ReportsMenu.cs

示例9: ExtractUriFromLink

 public static string ExtractUriFromLink(string relEndsWith, XDocument xml, XmlNamespaceManager namespaceManager)
 {
     return xml
         .XPathSelectElements("//dp:link/dp:rel", namespaceManager)
         .Where(element => element.Value.EndsWith(relEndsWith))
         .First()
         .XPathSelectElement("../dp:uri", namespaceManager)
         .Value;
 }
开发者ID:henningms,项目名称:digipost-hackathon-api-dotnet,代码行数:9,代码来源:Http.cs

示例10: AddReferencesFromProject

 private static void AddReferencesFromProject(DependencyGraphBuilder builder, object proj, XDocument xproject, string projectFile,
     HashSet<string> referencedProjects)
 {
     foreach (var xtarget in xproject.XPathSelectElements("/projectDescription/projects/project"))
     {
         var targetProjectName = xtarget.Value;
         if (!referencedProjects.Contains(targetProjectName))
             builder.AddProjectReference(proj, targetProjectName, null, null, null, ToLocation(projectFile, xtarget), null);
     }
 }
开发者ID:pescuma,项目名称:dependency-checker,代码行数:10,代码来源:EclipseProjectsLoader.cs

示例11: Execute

        public NBi.Core.ResultSet.ResultSet Execute(XDocument items)
        {
            var result = from item in items.XPathSelectElements(@from)
                         select GetObj(item);

            var builder = new ResultSetBuilder();
            var rows = result.ToArray();
            var resultSet = builder.Build(rows);
            return resultSet;
        }
开发者ID:Waltervondehans,项目名称:NBi,代码行数:10,代码来源:XPathEngine.cs

示例12: ProcessXML

    public int ProcessXML(XDocument file,string userid)
    {
        string level;
        SqlCommand sqlCmd1;
        SqlDataReader read1;
        SqlConnection sqlCon = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        sqlCon.Open();

        if (userid == null)
            userid = "PatientFolder";
        string FolderPath = @"D:\C sharp code\LongTermCare(Xml)\Search\Query_Xml\" + userid;
        DirectoryInfo DIFO = new DirectoryInfo(FolderPath);//判斷資料夾存在否
        if (!DIFO.Exists)
        {
            DIFO.Create();
        }

        level = file.Root.Name.ToString();
        IEnumerable<XElement> list1 = file.XPathSelectElements(level);//root node
        int Querycount = 0;
        foreach (XElement item in list1.Elements())
        {//get fieldname and value
            if (item.Value.ToString() != "")
            {
                QFieldName[Querycount] = item.Attribute("FieldName").Value.ToString().Replace(" ", "");
                QVR[Querycount] = item.Attribute("VR").Value.ToString();
                Qvalue[Querycount++] = item.Value.ToString();
            }
        }
        int checkwhere = 0;
        for (int i = 0; i < Querycount; i++)//saerch tablename then combine SQL
        {
            sqlCmd1 = new SqlCommand("select DISTINCT TableName from TableFields where FieldName='" + QFieldName[i] + "'", sqlCon);
            read1 = sqlCmd1.ExecuteReader();
            read1.Read();
            if (Qvalue[i] != "*")
            {
                if (++checkwhere == 1)
                    Terms = "where" + ' ' + Terms;
                Terms += read1["TableName"].ToString() + "." + QFieldName[i];
                if ((QVR[i] == "DA" || QVR[i] == "TM") && Qvalue[i].Length == 9)
                    Terms += Qvalue[i];
                else if ((QVR[i] == "DA" || QVR[i] == "TM") && Qvalue[i].Length > 9)
                {
                    string[] strs = Qvalue[i].Split('-');
                    Terms += ">" + strs[0] + " and " + read1["TableName"].ToString() + "." + QFieldName[i] + "<" + strs[1];
                }
                else
                    Terms += "=" + "'" + Qvalue[i] + "'";
                if (i < Querycount - 1)
                    Terms += ' ' + "and ";
            }
        }
        return Query(level, userid);
    }
开发者ID:GuojunSu,项目名称:RestMedical,代码行数:55,代码来源:search.cs

示例13: ResolveAbstractPatterns

        /// <summary>
        /// Resolves all abstract patterns in the schema by replacing
        /// parameter references by actual parameter values in all enclosed
        /// attributes that contain queries.
        /// </summary>
        /// <param name="xSchema">Validation schema</param>
        /// <param name="nsManager">Namespace manager</param>
        /// <exception cref="ArgumentNullException" />
        public static void ResolveAbstractPatterns(XDocument xSchema, XmlNamespaceManager nsManager)
        {
            if (xSchema == null)
            {
                throw new ArgumentNullException("xSchema");
            }

            if (nsManager == null)
            {
                throw new ArgumentNullException("nsManager");
            }

            // select abstract patterns
            Dictionary<string, XElement> dicAPs = new Dictionary<string, XElement>();
            foreach (XElement xAbstractPattern in xSchema.XPathSelectElements("//sch:pattern[@abstract='true']", nsManager))
            {
                string id = xAbstractPattern.Attribute(XName.Get("id")).Value;
                dicAPs.Add(id, xAbstractPattern);
            }

            if (dicAPs.Count > 0)
            {
                // select instances
                List<XElement> listInstances = new List<XElement>();
                foreach (XElement xInstance in xSchema.XPathSelectElements("//sch:pattern[@is-a]", nsManager))
                {
                    listInstances.Add(xInstance);
                }

                // replace instances
                foreach (XElement xInstance in listInstances)
                {
                    ReplaceAbstractPatternInstance(dicAPs, xInstance, nsManager);
                }

                // remove abstract patterns
                foreach (KeyValuePair<string, XElement> item in dicAPs)
                {
                    item.Value.Remove();
                }
            }
        }
开发者ID:xpekatt,项目名称:SchemaTron,代码行数:50,代码来源:Preprocessor.cs

示例14: MainWindow

        public MainWindow()
        {
            InitializeComponent();
            try
            {   
                // app.configista löytyvä viinit1.xml
                string wines = ConfigurationManager.AppSettings.Get("XMLFile");
                //ladataan xml-tiedosto
                doc = XDocument.Load(wines);
                
                //säätöä
                /**var query = from w in doc.Descendants("wine")
                            select new {
                                //nimi = w.Element("nimi").Value,
                                maa = w.Element("maa").Value,
                                //arvio = w.Element("arvio").Value
                            }; **/
                
               // maat comboboxiin
                foreach (var elem in doc.XPathSelectElements("//maa"))
                {                    
                    if (!cmbValinta.Items.Contains(elem.Value))
                    {
                        cmbValinta.Items.Add(elem.Value);
                    }
                 
                }
                
                // kaikki vinetot datagridiin
                foreach (var elem in doc.XPathSelectElements("//wine"))
                {
                    dgViinit.Items.Add(elem).ToString();

                }
                cmbValinta.Items.Add("Kaikki vinetot");
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erroria: " + ex.Message);
            }
        }               
开发者ID:g8605,项目名称:IIO11300,代码行数:42,代码来源:MainWindow.xaml.cs

示例15: GetLinks

        private static IEnumerable<Link> GetLinks(XDocument doc, Func<string, Link> factory)
        {
            var links  = new List<Link>();

            var reader = doc.CreateReader();
            var xmlNameTable = reader.NameTable;
            _NamespaceManager = new XmlNamespaceManager(xmlNameTable);
            _NamespaceManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

            var elements = doc.XPathSelectElements("//xhtml:link[@href]|//xhtml:a[@href]",_NamespaceManager);
            foreach(var linkElement in elements) {
                links.AddRange(CreateLinks(linkElement, factory));
            }

            var formElements = doc.XPathSelectElements("//xhtml:form[@action]", _NamespaceManager);
            foreach (var linkElement in formElements) {
                links.AddRange(CreateFormLinks(linkElement, factory));
            }
            return links;
        }
开发者ID:darrelmiller,项目名称:RESTAgent.Samples,代码行数:20,代码来源:MicroblogLinkExtractor.cs


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