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


C# IEnumerable.Descendants方法代码示例

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


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

示例1: GetBasicResponse

        protected Response GetBasicResponse(IEnumerable<XElement> root)
        {
            //populate the basic info
            // and see if the response is successful
            if (0 == root.Count()) {
                root = _doc.Descendants(_namespace + "ErrorResponse");
            }
            var resultCode = root.Descendants(_namespace + "resultCode").First().Value;
            var response = new Response
                               {
                                   Success = resultCode == "Ok" ? true : false,
                                   Message = root.Descendants(_namespace + "text").First().Value,
                                   Code = root.Descendants(_namespace + "code").First().Value

                               };
            return response;
        }
开发者ID:minhajuddin,项目名称:authnet_processor,代码行数:17,代码来源:ParserBase.cs

示例2: FindElementByAttributesFromElements

        protected XElement FindElementByAttributesFromElements(string attributeName, string attributeValue, IEnumerable<XElement> elements)
        {
            var descendants = elements
                .Descendants();

            var element = descendants
                .Where(x => x.HasAttributes && x.Attribute(attributeName) != null)
                .SingleOrDefault(x => x.Attribute(attributeName).Value == attributeValue);

            return element;
        }
开发者ID:mnasif786,项目名称:Business-Safe,代码行数:11,代码来源:BaseConfigTests.cs

示例3: GetTableValue

 public static string GetTableValue(IEnumerable<XElement> rows, string property)
 {
     string value;
         XElement propertyCell = rows.Descendants("td").Where(cell => cell.Value == property).FirstOrDefault();
         if (propertyCell != null)
         {
             var Row = propertyCell.Parent.Descendants("td").ElementAt(1);
             return Row.Value.Trim();
         }
         else
         {
             return string.Empty;
         }
 }
开发者ID:robcar,项目名称:getingarna,代码行数:14,代码来源:Utilities.cs

示例4: CopyComments

 private static void CopyComments(WordprocessingDocument oldDoc, WordprocessingDocument newDoc, IEnumerable<XElement> paragraphs)
 {
     int number = 0;
     XDocument oldComments = null;
     XDocument newComments = null;
     foreach (XElement comment in paragraphs.Descendants(ns + "commentReference"))
     {
         if (oldComments == null)
             oldComments = oldDoc.MainDocumentPart.WordprocessingCommentsPart.GetXDocument();
         if (newComments == null)
         {
             if (newDoc.MainDocumentPart.WordprocessingCommentsPart != null)
             {
                 newComments = newDoc.MainDocumentPart.WordprocessingCommentsPart.GetXDocument();
                 var ids = newComments.Root.Elements(ns + "comment").Select(f => (int)f.Attribute(ns + "id"));
                 if (ids.Any())
                     number = ids.Max() + 1;
             }
             else
             {
                 newDoc.MainDocumentPart.AddNewPart<WordprocessingCommentsPart>();
                 newComments = newDoc.MainDocumentPart.WordprocessingCommentsPart.GetXDocument();
                 newComments.Add(new XElement(ns + "comments", ns_attrs));
             }
         }
         string id = (string)comment.Attribute(ns + "id");
         XElement element = oldComments.Descendants().Elements(ns + "comment").Where(p => ((string)p.Attribute(ns + "id")) == id).First();
         XElement newElement = new XElement(element);
         newElement.Attribute(ns + "id").Value = number.ToString();
         newComments.Root.Add(newElement);
         comment.Attribute(ns + "id").Value = number.ToString();
         XElement commentRange = paragraphs.Elements(ns + "commentRangeStart").Where(s => ((string)s.Attribute(ns + "id")) == id).FirstOrDefault();
         if (commentRange != null)
             commentRange.Attribute(ns + "id").Value = number.ToString();
         commentRange = paragraphs.Elements(ns + "commentRangeEnd").Where(s => ((string)s.Attribute(ns + "id")) == id).FirstOrDefault();
         if (commentRange != null)
             commentRange.Attribute(ns + "id").Value = number.ToString();
         number++;
     }
 }
开发者ID:huamouse,项目名称:Taoqi,代码行数:40,代码来源:DocumentBuilder.cs

示例5: CopyHyperlinks

 private static void CopyHyperlinks(WordprocessingDocument oldDoc, WordprocessingDocument newDoc, IEnumerable<XElement> paragraphs)
 {
     foreach (XElement hyperlink in paragraphs.Descendants(ns + "hyperlink"))
         if (hyperlink.Attribute(ns_r + "id") != null)
         {
             string relId = hyperlink.Attribute(ns_r + "id").Value;
             HyperlinkRelationship relLink = oldDoc.MainDocumentPart.HyperlinkRelationships.Where(rel => (rel.Id == relId)).FirstOrDefault();
             HyperlinkRelationship newRelLink = newDoc.MainDocumentPart.AddHyperlinkRelationship(relLink.Uri, true);
             hyperlink.Attribute(ns_r + "id").Value = newRelLink.Id;
         }
     foreach (XElement hyperlink in paragraphs.Descendants(ns_v + "imagedata"))
         if (hyperlink.Attribute(ns_r + "href") != null)
         {
             string relId = hyperlink.Attribute(ns_r + "href").Value;
             ExternalRelationship relLink = oldDoc.MainDocumentPart.ExternalRelationships.Where(rel => (rel.Id == relId)).FirstOrDefault();
             ExternalRelationship newRelLink = newDoc.MainDocumentPart.AddExternalRelationship(relLink.RelationshipType, relLink.Uri);
             hyperlink.Attribute(ns_r + "href").Value = newRelLink.Id;
         }
 }
开发者ID:huamouse,项目名称:Taoqi,代码行数:19,代码来源:DocumentBuilder.cs

示例6: CopyEndnotes

 private static void CopyEndnotes(WordprocessingDocument oldDoc, WordprocessingDocument newDoc, IEnumerable<XElement> paragraphs)
 {
     int number = 0;
     XDocument oldEndnotes = null;
     XDocument newEndnotes = null;
     foreach (XElement endnote in paragraphs.Descendants(ns + "endnoteReference"))
     {
         if (oldEndnotes == null)
             oldEndnotes = oldDoc.MainDocumentPart.EndnotesPart.GetXDocument();
         if (newEndnotes == null)
         {
             if (newDoc.MainDocumentPart.EndnotesPart != null)
             {
                 newEndnotes = newDoc.MainDocumentPart.EndnotesPart.GetXDocument();
                 var ids = newEndnotes.Root.Elements(ns + "endnote").Select(f => (int)f.Attribute(ns + "id"));
                 if (ids.Any())
                     number = ids.Max() + 1;
             }
             else
             {
                 newDoc.MainDocumentPart.AddNewPart<EndnotesPart>();
                 newEndnotes = newDoc.MainDocumentPart.EndnotesPart.GetXDocument();
                 newEndnotes.Add(new XElement(ns + "endnotes", ns_attrs));
             }
         }
         string id = (string)endnote.Attribute(ns + "id");
         XElement element = oldEndnotes.Descendants().Elements(ns + "endnote").Where(p => ((string)p.Attribute(ns + "id")) == id).First();
         XElement newElement = new XElement(element);
         newElement.Attribute(ns + "id").Value = number.ToString();
         newEndnotes.Root.Add(newElement);
         endnote.Attribute(ns + "id").Value = number.ToString();
         number++;
     }
 }
开发者ID:huamouse,项目名称:Taoqi,代码行数:34,代码来源:DocumentBuilder.cs

示例7: AppendDocument

        private static void AppendDocument(this WordprocessingDocument doc, WordprocessingDocument source, IEnumerable<XElement> contents,
            bool keepSection, bool lastKeepSection, List<ImageData> images)
        {
            FixRanges(source.MainDocumentPart.GetXDocument(), contents);
            CopyReferences(source, doc, contents, images);

            // Append contents
            XDocument mainPart = doc.MainDocumentPart.GetXDocument();
            XElement section = mainPart.Root.Element(ns + "body").Element(ns + "sectPr");
            XElement newSection = contents.Last();
            if (newSection.Name != ns + "sectPr")
                newSection = null;
            if (newSection == null)
                keepSection = false;
            bool newContainsSection = contents.Descendants(ns + "pPr").Descendants(ns + "sectPr").Any();
            if (section != null)
            {
                section.Remove();
                if (lastKeepSection)
                {
                    if (newContainsSection || keepSection)
                    {
                        XElement paragraph = mainPart.Root.Element(ns + "body").Elements(ns + "p").Last();
                        XElement prop = paragraph.Element(ns + "pPr");
                        if (prop == null)
                        {
                            prop = new XElement(ns + "pPr");
                            paragraph.AddFirst(prop);
                        }
                        if (newContainsSection && !keepSection)
                            prop.Add(new XElement(section));
                        else
                            prop.Add(section);
                    }
                }
                else if (keepSection)
                    section = null;
            }
            mainPart.Root.Element(ns + "body").Add(contents);
            if (!keepSection && section != null)
            {
                newSection = mainPart.Root.Element(ns + "body").Element(ns + "sectPr");
                if (newSection != null)
                    newSection.Remove();
                mainPart.Root.Element(ns + "body").Add(section);
            }
        }
开发者ID:huamouse,项目名称:Taoqi,代码行数:47,代码来源:DocumentBuilder.cs

示例8: CopyCustomXml

 private static void CopyCustomXml(WordprocessingDocument sourceDocument, WordprocessingDocument newDocument,
     IEnumerable<XElement> newContent)
 {
     List<string> itemList = new List<string>();
     foreach (string itemId in newContent
         .Descendants(W.dataBinding)
         .Select(e => e.Attribute(W.storeItemID).Value))
         if (!itemList.Contains(itemId))
             itemList.Add(itemId);
     foreach (CustomXmlPart customXmlPart in sourceDocument.MainDocumentPart.CustomXmlParts)
     {
         OpenXmlPart propertyPart = customXmlPart
             .Parts
             .Select(p => p.OpenXmlPart)
             .Where(p => p.ContentType == "application/vnd.openxmlformats-officedocument.customXmlProperties+xml")
             .First();
         XDocument propertyPartDoc = propertyPart.GetXDocument();
         if (itemList.Contains(propertyPartDoc.Root.Attribute(DS.itemID).Value))
         {
             CustomXmlPart newPart = newDocument.MainDocumentPart.AddCustomXmlPart(customXmlPart.ContentType);
             newPart.GetXDocument().Add(customXmlPart.GetXDocument().Root);
             foreach (OpenXmlPart propPart in customXmlPart.Parts.Select(p => p.OpenXmlPart))
             {
                 CustomXmlPropertiesPart newPropPart = newPart.AddNewPart<CustomXmlPropertiesPart>();
                 newPropPart.GetXDocument().Add(propPart.GetXDocument().Root);
             }
         }
     }
 }
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:29,代码来源:DocumentBuilder.cs

示例9: CopyDiagrams

        private static void CopyDiagrams(WordprocessingDocument oldDoc, WordprocessingDocument newDoc, IEnumerable<XElement> paragraphs)
        {
            foreach (XElement diagramReference in paragraphs.Descendants(ns_dgm + "relIds"))
            {
                // dm attribute
                string relId = diagramReference.Attribute(ns_r + "dm").Value;
                OpenXmlPart oldPart = oldDoc.MainDocumentPart.GetPartById(relId);
                OpenXmlPart newPart = newDoc.MainDocumentPart.AddNewPart<DiagramDataPart>();
                newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
                diagramReference.Attribute(ns_r + "dm").Value = newDoc.MainDocumentPart.GetIdOfPart(newPart);

                // lo attribute
                relId = diagramReference.Attribute(ns_r + "lo").Value;
                oldPart = oldDoc.MainDocumentPart.GetPartById(relId);
                newPart = newDoc.MainDocumentPart.AddNewPart<DiagramLayoutDefinitionPart>();
                newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
                diagramReference.Attribute(ns_r + "lo").Value = newDoc.MainDocumentPart.GetIdOfPart(newPart);

                // qs attribute
                relId = diagramReference.Attribute(ns_r + "qs").Value;
                oldPart = oldDoc.MainDocumentPart.GetPartById(relId);
                newPart = newDoc.MainDocumentPart.AddNewPart<DiagramStylePart>();
                newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
                diagramReference.Attribute(ns_r + "qs").Value = newDoc.MainDocumentPart.GetIdOfPart(newPart);

                // cs attribute
                relId = diagramReference.Attribute(ns_r + "cs").Value;
                oldPart = oldDoc.MainDocumentPart.GetPartById(relId);
                newPart = newDoc.MainDocumentPart.AddNewPart<DiagramColorsPart>();
                newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
                diagramReference.Attribute(ns_r + "cs").Value = newDoc.MainDocumentPart.GetIdOfPart(newPart);
            }
        }
开发者ID:huamouse,项目名称:Taoqi,代码行数:33,代码来源:DocumentBuilder.cs

示例10: GetCoumnValue

 /// <summary>
 /// 지정된 컬럼의 값을 반환합니다.
 /// </summary>
 /// <param name="query"></param>
 /// <param name="FieldName"></param>
 /// <returns>double</returns>
 private static IEnumerable<double> GetCoumnValue(IEnumerable<XElement> query, string FieldName)
 {
     var query2 =
                from
                    oColumns in query.Descendants("Column")
                where (string)oColumns.Element("ID") == FieldName &&
                    oColumns.Elements("Value").Any()
                select
                    (double)oColumns.Element("Value");
     return query2;
 }
开发者ID:wldyd0210,项目名称:TEST,代码行数:17,代码来源:KIS_SD0030A_HRD.cs

示例11: XElementToDataTable

        /// <summary>
        /// XElement 형식을 DataTable로 변환합니다. 
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        private static System.Data.DataTable XElementToDataTable(IEnumerable<XElement> x)
        {
            var all = from p in x.Descendants("Columns") select p;

            XElement table = new XElement("Root");
            foreach (XElement xe in all)
            {

                XElement Row1 = new XElement("Row");

                foreach (XElement xe2 in xe.Descendants("Column"))
                {
                   var row2 = (from p in xe2.Descendants()
                               select
                                   new XElement(xe2.Element("ID").Value, xe2.Element("Value").Value)).First();


                   Row1.Add(row2);
                }

                table.Add(new XElement(Row1));

            }

            System.Data.DataTable dt = ToDataTable(table.ToString());

            return dt;
        }
开发者ID:wldyd0210,项目名称:TEST,代码行数:33,代码来源:KIS_SD0030A_HRD.cs

示例12: GetGridConvertToXML

        /// <summary>
        /// 화면에 보이는 메트릭스 구조로 XML 태그를 변환합니다.
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        private static XElement GetGridConvertToXML(IEnumerable<XElement> x)
        {
            var all = from p in x.Descendants("Cells") select p;

            XElement oXElement = new XElement("Root");
            foreach (XElement xe in all)
            {

                XElement Row1 = new XElement("Row");

                foreach (XElement xe2 in xe.Descendants("Cell"))
                {
                    var row2 = (from p in xe2.Descendants()
                                select
                                    new XElement(xe2.Element("ColumnUid").Value, xe2.Element("Value").Value)).First();


                    Row1.Add(row2);
                }

                oXElement.Add(new XElement(Row1));

            }

            return oXElement;
        }
开发者ID:wldyd0210,项目名称:TEST,代码行数:31,代码来源:KIS_TR0071F_HRD.cs

示例13: RemoveUnwantedElements

        static void RemoveUnwantedElements(IEnumerable<XElement> members)
        {
            string[] tagsSupportedByIntellisense =
            {
                "summary",
                "param",
                "returns",
                "exception",
            };

            string[] tagsToStrip =
            {
                "a",
                "img",
            };

            RemoveElements(from member in members
                           from element in member.Elements()
                           where !tagsSupportedByIntellisense.Contains(element.Name.LocalName, StringComparer.OrdinalIgnoreCase)
                           select element);

            RemoveElements(from element in members.Descendants()
                           where IsMarkedToSkip(element)
                           select element);

            StripElements(from element in members.Descendants()
                          where tagsToStrip.Contains(element.Name.LocalName, StringComparer.OrdinalIgnoreCase)
                          select element);
        }
开发者ID:Himansh1306,项目名称:Win2D,代码行数:29,代码来源:Program.cs

示例14: ResetNumbering

		public void ResetNumbering(IEnumerable<XElement> elements)
		{
			var numPrs = elements.Descendants(W.numPr).Where(d=>d.Element(W.numId) != null);

			foreach (var numPr in numPrs.GroupBy(e => (int)e.Element(W.numId).Attribute(W.val)))
			{
				var numId = numPr.Key;
				var numIds = numPrs.Elements(W.numId).Attributes(W.val).Where(e => (int)e == numId);
				var ilvl = int.Parse(numPr.First().Element(W.ilvl).Attribute(W.val).Value);

				if (_lastNumIds.ContainsKey(ilvl))
				{

					var numElementPrototype = _numberingPart
					.Descendants(W.num)
					.FirstOrDefault(n => (int)n.Attribute(W.numId) == numId);

					var abstractNumElementPrototype = _numberingPart
						.Descendants(W.abstractNum)
						.FirstOrDefault(e => e.Attribute(W.abstractNumId).Value ==
								numElementPrototype
								.Element(W.abstractNumId)
								.Attribute(W.val).Value);
					var lastNumElement = _numberingPart
						.Descendants(W.num)
						.OrderBy(n => (int)n.Attribute(W.numId))
						.LastOrDefault();
					if (lastNumElement == null) break;

					var nextNumId = (int)lastNumElement.Attribute(W.numId) + 1;

					var lastAbstractNumElement = _numberingPart.Descendants(W.abstractNum).Last();
					var lastAbstractNumId = (int)lastAbstractNumElement.Attribute(W.abstractNumId);

					var newAbstractNumElement = new XElement(abstractNumElementPrototype);
					newAbstractNumElement.Attribute(W.abstractNumId).SetValue(lastAbstractNumId + 1);

					var next = Random.Next(int.MaxValue);
					var nsid = newAbstractNumElement.Element(W.nsid);
					if (nsid != null)
						nsid.Attribute(W.val).SetValue(next.ToString("X"));

					lastAbstractNumElement.AddAfterSelf(newAbstractNumElement);

					var newNumElement = new XElement(numElementPrototype);
					newNumElement.Attribute(W.numId).SetValue(nextNumId);
					newNumElement.Element(W.abstractNumId).Attribute(W.val).SetValue(lastAbstractNumId + 1);
					lastNumElement.AddAfterSelf(newNumElement);

					foreach (var xElement in numIds)
					{
						xElement.SetValue(nextNumId);
					}

					_lastNumIds[ilvl] = nextNumId;
				}
				else
				{
					_lastNumIds.Add(ilvl, numId);
				}
			}
		}
开发者ID:BorisVaskin,项目名称:TemplateEngine.Docx,代码行数:62,代码来源:NumberingAccessor.cs

示例15: CopyFooters

 private static void CopyFooters(WordprocessingDocument oldDoc, WordprocessingDocument newDoc, IEnumerable<XElement> paragraphs, List<ImageData> images)
 {
     foreach (XElement footerReference in paragraphs.Descendants(ns + "footerReference"))
     {
         string relId = footerReference.Attribute(ns_r + "id").Value;
         FooterPart oldPart = (FooterPart)oldDoc.MainDocumentPart.GetPartById(relId);
         XDocument oldFooter = oldPart.GetXDocument();
         FooterPart newPart = newDoc.MainDocumentPart.AddNewPart<FooterPart>();
         XDocument newFooter = newPart.GetXDocument();
         newFooter.Add(oldFooter.Root);
         footerReference.Attribute(ns_r + "id").Value = newDoc.MainDocumentPart.GetIdOfPart(newPart);
         CopyFooterShapes(oldPart, newPart, images);
         CopyFooterEmbeddedObjects(oldPart, newPart);
         CopyFooterImages(oldPart, newPart, images);
     }
 }
开发者ID:huamouse,项目名称:Taoqi,代码行数:16,代码来源:DocumentBuilder.cs


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