當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.ElementsAfterSelf方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.ElementsAfterSelf方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.ElementsAfterSelf方法的具體用法?C# XElement.ElementsAfterSelf怎麽用?C# XElement.ElementsAfterSelf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.ElementsAfterSelf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetRowSeats

        protected static XElement SetRowSeats(SeatPattern seatPattern, SeatsOrder seatsOrder, string rowName,
            IEnumerable<DataRow> filteredSeats, XElement currentElement)
        {
            currentElement.SetAttributeValue("data-row", rowName);

            // TODO : Verify this is always true: what if rows shouldn't always be left o right
            currentElement.ReorderElements(OrderBy.MinX);

            var currentPathElement = currentElement.Descendants().First();

            var rowSeats = GetOrderedSeatsForRow(filteredSeats, rowName, seatsOrder);
            switch (seatPattern)
            {
                case SeatPattern.Odds:
                    rowSeats = rowSeats.Where(x => int.Parse(x["seat_num"].ToString())%2 != 0);
                    break;
                case SeatPattern.Even:
                    rowSeats = rowSeats.Where(x => int.Parse(x["seat_num"].ToString())%2 == 0);
                    break;
            }

            foreach (var seat in rowSeats)
            {
                currentPathElement = SetElementAndGetNext(currentPathElement, seat);
                if (currentPathElement == null) break;
            }

            currentElement = currentElement.ElementsAfterSelf().FirstOrDefault();
            return currentElement;
        }
開發者ID:MerrittMelker,項目名稱:Ks.Ts.SeatsSvgHydrator,代碼行數:30,代碼來源:SeatSvgHydrator.cs

示例2: Parse

        /// <summary>
        ///   Parses the specified notification element.
        /// </summary>
        /// <param name = "notificationElement">The notification element.</param>
        /// <returns></returns>
        public ConstantEntity Parse(TypedEntity typedEntity, XElement notificationElement)
        {
            ConstantEntity notificationEntity = new ConstantEntity();
            notificationEntity.Type = "NSString";

            // Get the name
            notificationEntity.Name = notificationElement.TrimAll();

            this.Logger.WriteLine("  Notification '" + notificationEntity.Name + "'");

            // Get the content and the discussion
            XElement summaryElement = (from el in notificationElement.ElementsAfterSelf("section")
                                       where (String) el.Attribute("class") == "spaceabove"
                                       select el).FirstOrDefault();
            if (summaryElement != null)
            {
                foreach (XElement element in summaryElement.Elements())
                {
                    notificationEntity.Summary.Add(element.Value.TrimAll());
                }
            }

            // Get the availability
            String minAvailability = (from el in notificationElement.ElementsAfterSelf("div").Elements("ul").Elements("li")
                                      where (String) el.Parent.Parent.Attribute("class") == "api availability"
                                      select el.Value).FirstOrDefault();
            notificationEntity.MinAvailability = CommentHelper.ExtractAvailability(minAvailability.TrimAll());

            return notificationEntity;
        }
開發者ID:Monobjc,項目名稱:monobjc-tools,代碼行數:35,代碼來源:XhtmlCocoaNotificationParser.cs

示例3: Parse

        /// <summary>
        ///   Parses the specified constant element.
        /// </summary>
        /// <param name = "constantElement">The constant element.</param>
        public List<BaseEntity> Parse(TypedEntity typedEntity, XElement constantElement)
        {
            // Get the name
            String name = constantElement.TrimAll ();

            // Get the abstract
            XElement summaryElement = (from el in constantElement.ElementsAfterSelf ("p")
                                       where (String)el.Attribute ("class") == "abstract"
                                       select el).FirstOrDefault ();
            String summary = summaryElement.TrimAll ();

            // Get the declaration
            XElement declarationElement = (from el in constantElement.ElementsAfterSelf ("pre")
                                           where (String)el.Attribute ("class") == "declaration"
                                           select el).FirstOrDefault ();
            String declaration = declarationElement.TrimAll ();

            // Make various tests
            bool isDefine = declaration.StartsWith ("#define");
            bool isEnum = declaration.StartsWith ("enum") || declaration.StartsWith ("typedef enum") || declaration.Contains (" enum ");

            if (isDefine) {
                List<BaseEntity> entities = ExtractDefine (constantElement, name, summary, declaration);
                return entities;
            }

            if (isEnum) { // keep newlines for enum processing
                List<BaseEntity> entities = this.ExtractEnumeration (constantElement, name, summary, declarationElement.TrimSpaces());
                if (entities != null) {
                    return entities;
                }
            }

            return this.ExtractConstants (constantElement, name, summary, declaration);
        }
開發者ID:Monobjc,項目名稱:monobjc-tools,代碼行數:39,代碼來源:XhtmlCocoaConstantParser.cs

示例4: NextSdtElements

 public static IEnumerable<XElement> NextSdtElements(XElement startElement, IEnumerable<XName> names)
 {
     var namesList = names.ToList();
     var nextTagsInnerElements = GoDeeper(startElement, namesList).ToList();
     if (nextTagsInnerElements.Any())
     {
         return nextTagsInnerElements;
     }
     if (startElement == null)
     {
         throw new ArgumentNullException("startElement");
     }
     var nextTagElements = startElement.ElementsAfterSelf().Where(MakeSdtMatchingPredicate(namesList)).ToList();
     return nextTagElements.Any() ? nextTagElements : GoUp(startElement, namesList);
 }
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:15,代碼來源:TraverseUtils.cs

示例5: NextTagElements

 public static IEnumerable<XElement> NextTagElements(XElement startElement, IEnumerable<string> tagNames)
 {
     if (startElement == null)
     {
         throw new ArgumentNullException(string.Format("Argument {0} cannot be null", "startElement"));
     }
     if (tagNames == null)
     {
         throw new ArgumentNullException(string.Format("Argument {0} cannot be null", "tagNames"));
     }
     var namesList = tagNames.Select(s => s.ToLower()).ToList();
     var nextTagsInnerElements = GoDeeper(startElement, namesList).ToList();
     if (nextTagsInnerElements.Any())
     {
         return nextTagsInnerElements;
     }
     var nextTagElements = startElement.ElementsAfterSelf(WordMl.SdtName).Where(MakeTagMatchingPredicate(namesList)).ToList();
     return nextTagElements.Any() ? nextTagElements : GoUp(startElement, namesList);
 }
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:19,代碼來源:TraverseUtils.cs

示例6: ElementsBetween

 public static IEnumerable<XElement> ElementsBetween(XElement startElement, XElement endElement)
 {
     if (startElement == null)
     {
         throw new ArgumentNullException("startElement");
     }
     if (endElement == null)
     {
         throw new ArgumentNullException("endElement");
     }
     if (startElement.Parent.Equals(endElement.Parent))
     {
         return startElement.ElementsAfterSelf().Where(e => e.IsBefore(endElement));               
     }
     var commonParent = startElement.Ancestors().Intersect(endElement.Ancestors()).FirstOrDefault();
     if (commonParent == null)
     {
         return Enumerable.Empty<XElement>();
     }
     var endElementFirstLevel = commonParent.Elements().First(e => e.Descendants().Contains(endElement) || e.Equals(endElement));
     var startElementFirstLevel = commonParent.Elements().First(e => e.Descendants().Contains(startElement) || e.Equals(startElement));
     var afterStart = startElement.ElementsAfterSelf();
     var between = ElementsBetween(startElementFirstLevel, endElementFirstLevel);
     var beforeEnd = endElementFirstLevel.DescendantsBefore(endElement);
     return afterStart.Union(between).Union(beforeEnd);
 }
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:26,代碼來源:TraverseUtils.cs

示例7: GoDeeper

        private static IEnumerable<XElement> GoDeeper(XElement startElement, ICollection<XName> names)
        {
            if (startElement == null)
            {
                throw new ArgumentNullException("startElement");
            }
            if (names == null)
            {
                throw new ArgumentNullException("names");
            }
            var tagsElements = startElement.Descendants().Where(MakeSdtMatchingPredicate(names)).ToList();
            var isAnyTagsElement = tagsElements.Any();

            return isAnyTagsElement
                       ? tagsElements
                       : startElement.ElementsAfterSelf()
                                     .DescendantsAndSelf()
                                     .Where(MakeSdtMatchingPredicate(names));

        }
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:20,代碼來源:TraverseUtils.cs

示例8: SecondElementsBetween

 // TODO make one second elements between       
 public static IEnumerable<XElement> SecondElementsBetween(XElement startElement, XElement endElement, bool nested = false)
 {
     if (startElement == null)
     {
         throw new ArgumentNullException("startElement");
     }
     if (endElement == null)
     {
         throw new ArgumentNullException("endElement");
     }
     if (startElement.Equals(endElement))
     {
         return Enumerable.Empty<XElement>();
     }
     if (startElement.Parent.Equals(endElement.Parent))
     {                
         var oneLevelElements = new List<XElement>();
         if (nested)
         {
             oneLevelElements.Add(startElement);
         }
         oneLevelElements.AddRange(startElement.ElementsAfterSelf().Where(e => e.IsBefore(endElement)));                
         return oneLevelElements.AsEnumerable();               
     }
     var currentElement = startElement.NextElementWithUpTransition();
     var elements = new List<XElement>();
     while ((currentElement != null) && (currentElement != endElement))
     {
         if (currentElement.HasElements && currentElement.Descendants().Contains(endElement))
         {
             elements.AddRange(SecondElementsBetween(currentElement.Elements().First(), endElement, true));
             break;                    
         }
         elements.Add(currentElement);
         currentElement = currentElement.NextElementWithUpTransition();
     }
     return elements;
 }
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:39,代碼來源:TraverseUtils.cs

示例9: NodeElementsAfterSelf

        public void NodeElementsAfterSelf()
        {
            XElement parent = new XElement("parent");

            XElement child1a = new XElement("child1", new XElement("nested"));
            XElement child1b = new XElement("child1", new XElement("nested"));
            XElement child2a = new XElement("child2", new XElement("nested"));
            XElement child2b = new XElement("child2", new XElement("nested"));

            XComment comment = new XComment("this is a comment");

            // If no parent, should not be any elements before it.
            Assert.Empty(comment.ElementsAfterSelf());

            parent.Add(child1a);
            parent.Add(comment);
            parent.Add(child1b);
            parent.Add(child2a);
            parent.Add(child2b);

            Assert.Equal(new XElement[] { child1b, child2a, child2b }, comment.ElementsAfterSelf());

            Assert.Equal(new XElement[] { child1b }, comment.ElementsAfterSelf("child1"));

            Assert.Equal(new XElement[] { child1b }, child1a.ElementsAfterSelf("child1"));

            Assert.Empty(child2b.ElementsAfterSelf());
        }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:28,代碼來源:SDMNode.cs

示例10: ExtractEnumeration

        private List<BaseEntity> ExtractEnumeration(XElement constantElement, String name, String summary, String declaration)
        {
            declaration = declaration.Trim (';');

            // Default values
            String type = "NOTYPE";
            String values = String.Empty;

            // Match the enumeration definition
            bool result = this.SplitEnumeration (declaration, ref name, ref type, ref values);
            if (!result) {
                return null;
            }

            if (type == "NOTYPE") {
                type = RefineEnumBaseType(values);
            }

            // Create the enumeration
            EnumerationEntity enumerationEntity = new EnumerationEntity ();
            enumerationEntity.Name = name;
            enumerationEntity.BaseType = type;
            enumerationEntity.Namespace = "MISSING";
            enumerationEntity.Summary.Add (summary);

            // Parse the values
            var pairs = values.Split (new []{'\n'}, StringSplitOptions.RemoveEmptyEntries);
            foreach (string immutablePair in pairs) {
                String key;
                String value = String.Empty;
                String pair = immutablePair.Replace(",","");

                // Handle value assignment
                if (pair.IndexOf ('=') != -1) {
                    string[] parts = pair.Split (new []{'='}, StringSplitOptions.RemoveEmptyEntries);
                    key = parts [0].Trim ();
                    value = parts [1].Trim ();
                } else {
                    key = pair.Trim ();
                }

                // Add a new value
                EnumerationValueEntity enumerationValueEntity = new EnumerationValueEntity ();
                enumerationValueEntity.Name = key;

                if (value.Length == 6 && value.StartsWith ("'") && value.EndsWith ("'")) {
                    String v = value.Trim ('\'');
                    enumerationValueEntity.Value = "0x" + FourCharToInt (v).ToString ("X8");
                } else {
                    enumerationValueEntity.Value = value;
                }

                // Convert number qualifiers from native to managed
                enumerationValueEntity.Value = ConvertNumericQualifier (enumerationValueEntity.Value);

                enumerationEntity.Values.Add (enumerationValueEntity);
            }

            // Get the definitions
            XElement termList = (from el in constantElement.ElementsAfterSelf ("dl")
                                 where (String)el.Attribute ("class") == "termdef"
                                 select el).FirstOrDefault ();
            if (termList != null) {
                IEnumerable<XElement> dtList = termList.Elements ("dt");
                IEnumerable<XElement> ddList = termList.Elements ("dd");

                if (dtList.Count () == ddList.Count ()) {
                    // Iterate over definitions
                    for (int i = 0; i < dtList.Count(); i++) {
                        String term = dtList.ElementAt (i).Value.TrimAll ();
                        IEnumerable<String> summaries = ddList.ElementAt (i).Elements ("p").Select (p => p.Value.TrimAll ());

                        // Find the enumeration value
                        EnumerationValueEntity enumerationValueEntity = enumerationEntity.Values.Find (v => v.Name == term);
                        if (enumerationValueEntity != null) {
                            foreach (string sum in summaries) {
                                if (CommentHelper.IsAvailability (sum)) {
                                    enumerationValueEntity.MinAvailability = CommentHelper.ExtractAvailability (sum);
                                    break;
                                }
                                enumerationValueEntity.Summary.Add (sum);
                            }
                        } else {
                            this.Logger.WriteLine ("Term with no match '" + term + "'");
                        }
                    }
                } else {
                    this.Logger.WriteLine ("MISMATCH in terms");
                }
            }

            // Make sure availability is ok
            enumerationEntity.AdjustAvailability ();

            return new List<BaseEntity> {enumerationEntity};
        }
開發者ID:Monobjc,項目名稱:monobjc-tools,代碼行數:96,代碼來源:XhtmlCocoaConstantParser.cs

示例11: ExtractConstants

        private List<BaseEntity> ExtractConstants(XElement constantElement, String name, String summary, String declaration)
        {
            List<BaseEntity> constants = new List<BaseEntity> ();

            // Extract types and names
            string[] declarations = declaration.Split (new []{';'}, StringSplitOptions.RemoveEmptyEntries);
            foreach (string part in declarations) {
                //this.Logger.WriteLine("Parsing constant '{0}'...", part.Trim());

                String stripped = part.Trim ();
                stripped = stripped.Replace ("extern", String.Empty);
                stripped = stripped.Replace ("const", String.Empty);
                stripped = stripped.TrimAll ();

                Match r = CONSTANT_REGEX.Match (stripped);
                if (r.Success) {
                    String type = r.Groups [1].Value.Trim (' ', '*', ' ');

                    bool isOut;
                    bool isByRef;
                    bool isBlock;
                    type = this.TypeManager.ConvertType (type, out isOut, out isByRef, out isBlock, this.Logger);

                    ConstantEntity constantEntity = new ConstantEntity ();
                    constantEntity.Type = type;
                    constantEntity.Name = r.Groups [2].Value.Trim ();
                    constants.Add (constantEntity);

                    //this.Logger.WriteLine("Constant found '{0}' of type '{1}'", constantEntity.Name, constantEntity.Type);
                } else {
                    this.Logger.WriteLine ("FAILED to parse constant '{0}'", stripped);
                    return null;
                }
            }

            // Get the definitions
            XElement termDefinitions = (from el in constantElement.ElementsAfterSelf ("dl")
                                        where (String)el.Attribute ("class") == "termdef"
                                        select el).FirstOrDefault ();
            if (termDefinitions == null) {
                this.Logger.WriteLine ("MISSING terms");
                return null;
            }

            IEnumerable<XElement> termName = termDefinitions.Elements ("dt");
            IEnumerable<XElement> termDefinition = termDefinitions.Elements ("dd");

            if (termName.Count () == termDefinition.Count ()) {
                // Iterate over definitions
                for (int i = 0; i < termName.Count(); i++) {
                    String term = termName.ElementAt (i).Value.TrimAll ();
                    IEnumerable<String> summaries = termDefinition.ElementAt (i).Elements ("p").Select (p => p.Value.TrimAll ());

                    // Find the enumeration value
                    BaseEntity baseEntity = constants.Find (c => c.Name == term);
                    if (baseEntity != null) {
                        foreach (string sum in summaries) {
                            if (CommentHelper.IsAvailability (sum)) {
                                baseEntity.MinAvailability = CommentHelper.ExtractAvailability (sum);
                                break;
                            }
                            baseEntity.Summary.Add (sum);
                        }
                    } else {
                        this.Logger.WriteLine ("Term with no match '" + term + "'");
                    }
                }
            } else {
                this.Logger.WriteLine ("MISMATCH in terms");
                return null;
            }

            return constants;
        }
開發者ID:Monobjc,項目名稱:monobjc-tools,代碼行數:74,代碼來源:XhtmlCocoaConstantParser.cs

示例12: GetNameWithIndex

        private static string GetNameWithIndex(XElement element)
        {
            // numbering starts with 1
            var index = element.ElementsBeforeSelf(element.Name).Count() + 1;

            // add index only when there are more then 1 elements
            if (index == 1 && !element.ElementsAfterSelf(element.Name).Any()) return element.Name.ToString();

            return element.Name + "[" + index + "]";;
        }
開發者ID:Catrobat,項目名稱:CatrobatForWindows,代碼行數:10,代碼來源:XPathHelper.cs

示例13: IsRepeated

 public bool IsRepeated(XElement element)
 {
     return element.ElementsAfterSelf(Name).Any();
 }
開發者ID:ststeiger,項目名稱:XmlToCSharp,代碼行數:4,代碼來源:Class.cs

示例14: Parse

        /// <summary>
        ///   Parses the specified method element.
        /// </summary>
        /// <param name = "functionElement">The function element.</param>
        /// <returns></returns>
        public FunctionEntity Parse(TypedEntity typedEntity, XElement functionElement)
        {
            FunctionEntity functionEntity = new FunctionEntity ();

            // Extract name
            String name = functionElement.TrimAll ();
            functionEntity.Name = name;

            this.Logger.WriteLine ("  Function '" + name + "'");

            // Extract abstract
            XElement abstractElement = (from el in functionElement.ElementsAfterSelf ("p")
                                        where (String)el.Attribute ("class") == "abstract"
                                        select el).FirstOrDefault ();
            functionEntity.Summary.Add (abstractElement.TrimAll ());

            // Extract declaration
            XElement declarationElement = (from el in functionElement.ElementsAfterSelf ("pre")
                                           where (String)el.Attribute ("class") == "declaration"
                                           select el).FirstOrDefault ();

            String signature = declarationElement.TrimAll ();
            if (signature.StartsWith ("#define")) {
                this.Logger.WriteLine ("SKIPPING define statement: " + name);
                return null;
            }
            if (signature.StartsWith ("typedef")) {
                this.Logger.WriteLine ("SKIPPING define statement: " + name);
                return null;
            }
            if (!signature.Contains ("(")) { // e.g. NS_DURING
                this.Logger.WriteLine ("SKIPPING non-function statement: " + name);
                return null;
            }

            // Trim down signature
            while (signature.IndexOf("  ") != -1) {
                signature = signature.Replace ("  ", " ");
            }
            while (signature.IndexOf(" (") != -1) {
                signature = signature.Replace (" (", "(");
            }
            functionEntity.Signature = signature;
            //Console.WriteLine("name='" + name + "' signature='" + signature + "'");

            // Parse signature
            int pos = signature.IndexOf (name + "(");
            if (pos == -1) {
                this.Logger.WriteLine ("MISMATCH between name and declaration: " + name);
                return null;
            }
            String returnType = signature.Substring (0, pos).Trim ();
            int paramsIndex = pos + name.Length;
            int paramsLength = signature.IndexOf(')') + 1 - paramsIndex; // Stop before getting to function body
            String parameters = signature.Substring (paramsIndex, paramsLength).Trim ();
            parameters = parameters.Trim (';', '(', ')').Trim();
            if (parameters != "void") {
                foreach (string parameter in parameters.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries)) {
                    String parameterType = "NOTYPE";
                    String parameterName = "NONAME";

                    //Console.WriteLine("parameter='" + parameter + "'");
                    Match r = PARAMETER_REGEX.Match (parameter);
                    if (r.Success) {
                        parameterType = r.Groups [2].Value.Trim ();
                        parameterName = r.Groups [3].Value.Trim ();
                    } else if (parameter.Trim () == "...") {
                        parameterType = "params Object[]";
                        parameterName = "values";
                    } else {
                        this.Logger.WriteLine ("FAILED to parse parameter: " + parameter);
                        return null;
                    }
                    parameterType = parameterType.Trim ();

                    MethodParameterEntity parameterEntity = new MethodParameterEntity ();
                    bool isOut, isByRef, isBlock;
                    parameterEntity.Type = this.TypeManager.ConvertType (parameterType, out isOut, out isByRef, out isBlock, this.Logger);
                    parameterEntity.IsOut = isOut;
                    parameterEntity.IsByRef = isByRef;
                    parameterEntity.IsBlock = isBlock;
                    parameterEntity.Name = TypeManager.ConvertName(parameterName);
                    functionEntity.Parameters.Add (parameterEntity);
                }
            }

            // Extract return type
            functionEntity.ReturnType = this.TypeManager.ConvertType (returnType, this.Logger);

            // Extract parameter documentation
            if (functionEntity.Parameters.Count > 0) {
                XElement termList = (from el in functionElement.Elements ("div").Elements ("dl")
                                     where (String)el.Parent.Attribute ("class") == "api parameters"
                    && (String)el.Attribute ("class") == "termdef"
                                     select el).FirstOrDefault ();
//.........這裏部分代碼省略.........
開發者ID:Monobjc,項目名稱:monobjc-tools,代碼行數:101,代碼來源:XhtmlCocoaFunctionParser.cs

示例15: SetElementAndGetNext

 protected static XElement SetElementAndGetNext(XElement element, DataRow seat)
 {
     element.Attributes().Where(x => x.Name.LocalName == "class").Remove();
     element.SetAttributeValue("data-seat-row", seat["seat_row"].ToString().Trim());
     element.SetAttributeValue("data-seat-num", seat["seat_num"].ToString().Trim());
     //element.SetAttributeValue("data-seat-status", seat["seat_status"].ToString().Trim());
     element.SetAttributeValue("id", seat["seat_no"].ToString().Trim());
     //element.SetAttributeValue("data-zone", seat["zone_no"].ToString().Trim());
     return element.ElementsAfterSelf().FirstOrDefault();
 }
開發者ID:MerrittMelker,項目名稱:Ks.Ts.SeatsSvgHydrator,代碼行數:10,代碼來源:SeatSvgHydrator.cs


注:本文中的System.Xml.Linq.XElement.ElementsAfterSelf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。