本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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());
}
示例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};
}
示例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;
}
示例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 + "]";;
}
示例13: IsRepeated
public bool IsRepeated(XElement element)
{
return element.ElementsAfterSelf(Name).Any();
}
示例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 ();
//.........这里部分代码省略.........
示例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();
}