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


C# XElement.DescendantsAndSelf方法代码示例

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


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

示例1: XElementContext

        public XElementContext(XElement root, XizzleConventions conventions = null)
        {
            Conventions = conventions ?? DefaultConventions;
            RootElement = root;

            _idDict = new Dictionary<string, XElement>();
            _typeDict = new Dictionary<string, HashSet<XElement>>();
            _attrDict = new Dictionary<string, HashSet<XElement>>();

            foreach (var el in RootElement.DescendantsAndSelf())
            {
                IEnumerable<XAttribute> nameAttributes = el.Attributes()
                    .Where(a => a.Name.LocalName == Conventions.IdAttributeName());

                foreach (XAttribute attr in nameAttributes)
                    _idDict[attr.Value] = el;

                if (!_typeDict.ContainsKey(el.Name.LocalName))
                    _typeDict[el.Name.LocalName] = new HashSet<XElement>();
                _typeDict[el.Name.LocalName].Add(el);

                foreach (XAttribute a in el.Attributes())
                {
                    if (!_attrDict.ContainsKey(a.Name.LocalName))
                        _attrDict[a.Name.LocalName] = new HashSet<XElement>();
                    _attrDict[a.Name.LocalName].Add(el);
                }
            }
        }
开发者ID:xinmyname,项目名称:xizzle,代码行数:29,代码来源:XElementContext.cs

示例2: CProfile

 public CProfile(XElement xml)
 {
     foreach (XElement item in xml.DescendantsAndSelf ("row"))
     {
      //   ProfileItems.Add(CService.GetString(item, "profileItem"), CService.GetObject(item, "value", CService.GetString(item, "type")));
     }
 }
开发者ID:serdarkaracay,项目名称:SLSpa,代码行数:7,代码来源:CProfile.cs

示例3: GetXElement

 /// <summary>
 /// 获取XElement文件树节点段XElement
 /// </summary>
 /// <param name="xml">XElement文件载体</param>
 /// <param name="mainnode">要查找的主节点</param>
 /// <param name="attribute">主节点条件属性名</param>
 /// <param name="value">主节点条件属性值</param>
 /// <returns>以该主节点为根的XElement</returns>
 public static XElement GetXElement(XElement XElement, string newroot, string attribute, string value)
 {
     if (XElement != null)
     {
         IEnumerable<XElement> xmlItems = XElement.DescendantsAndSelf(newroot);
         if (xmlItems != null)
         {
             foreach (var xmlItem in xmlItems)
             {
                 XAttribute attrib = null;
                 if (xmlItem != null)
                     attrib = xmlItem.Attribute(attribute);
                 if (null != attrib && attrib.Value == value)
                 {
                     return xmlItem;
                 }
             }
         }
         return null;
     }
     else
     {
         DebugMod.LogError(new Exception(string.Format("GetXElement异常, 读取: {0}/{1}={2} 失败, xml节点名: {3}", newroot, attribute, value, GetXElementNodePath(XElement))));
         return null;
     }
 }
开发者ID:yuisunn,项目名称:UnityCrazy,代码行数:34,代码来源:XMLMod.cs

示例4: ReplaceFormTagByDivTag

		internal static void ReplaceFormTagByDivTag(XElement document)
		{
			foreach (var form in document.DescendantsAndSelf(ns + "form"))
			{
				form.Name = ns + "div";
			}
		}
开发者ID:JustAndrei,项目名称:C1-Packages,代码行数:7,代码来源:Helper.cs

示例5: GetMergeScript

    public static XElement GetMergeScript(string start, string dest)
    {
      if (string.IsNullOrWhiteSpace(start))
        return new XElement("AML");

      var startElem = XElement.Parse(start);
      var result = new XElement(startElem.Name);

      // Create deletes
      if (string.IsNullOrEmpty(dest))
      {
        var itemTag = startElem.DescendantsAndSelf().First(e => e.Name.LocalName == "Item");
        var items = itemTag.Parent.Elements("Item").Where(e => e.Attribute("action") != null
          && (e.Attribute("action").Value == "merge" || e.Attribute("action").Value == "add"
            || e.Attribute("action").Value == "create"));
        XElement newItem;
        foreach (var item in items)
        {
          newItem = new XElement(item.Name, item.Attributes().Where(IsAttributeToCopy));
          newItem.SetAttributeValue("action", "delete");
        }
        return result;
      }

      // Create merges/deletes as necessary
      var destElem = XElement.Parse(dest);
      GetMergeScript(startElem, destElem, result);
      foreach (var elem in result.DescendantsAndSelf())
        elem.RemoveAnnotations<ElementKey>();
      return result;
    }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:31,代码来源:AmlDiff.cs

示例6: Parse

 public LastfmResponse<LastfmUserItem> Parse(XElement xmlResponse)
 {
     lfmNodeErrorParser.Parse(xmlResponse);
       var tracks = xmlResponse.DescendantsAndSelf(CollectionElementName);
       var tracksElement = tracks.First();
       return CreateUserItem(tracksElement);
 }
开发者ID:asciamanna,项目名称:LastfmClient,代码行数:7,代码来源:BaseUserResponseParser.cs

示例7: ReadReferencedAssemblyNames

 private List<string> ReadReferencedAssemblyNames(XElement xml)
 {
     List<string> rawAssemblyNames = (from r in xml.DescendantsAndSelf(Ns + "Reference")
                                      where r.Parent.Name == Ns + "ItemGroup"
                                      select r.Attribute("Include").Value).ToList();
     List<string> unQualifiedAssemblyNames = rawAssemblyNames.ConvertAll(UnQualify);
     return unQualifiedAssemblyNames;
 }
开发者ID:HKochniss,项目名称:SlimJim,代码行数:8,代码来源:CsProjReader.cs

示例8: Parse

        public LastfmResponse<LastfmLibraryItem> Parse(XElement xmlResponse)
        {
            lfmNodeErrorParser.Parse(xmlResponse);
              var collection = xmlResponse.DescendantsAndSelf(CollectionElementName);
              var collectionElement = collection.First();

              return CreateLibraryItem(collectionElement);
        }
开发者ID:asciamanna,项目名称:LastfmClient,代码行数:8,代码来源:BaseLibraryResponseParser.cs

示例9: RemoveDebugInfo

 private static void RemoveDebugInfo(IScope scope, XElement result) {
     if (!scope.Get("debug_render", false)) {
         foreach (var element in result.DescendantsAndSelf()) {
             element.SetAttributeValue("_file", null);
             element.SetAttributeValue("_line", null);
         }
     }
 }
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:8,代码来源:XmlInterpolationReportRender.cs

示例10: GetNzbInfoUrl

 protected override string GetNzbInfoUrl(XElement item)
 {
     IEnumerable<XElement> matches = item.DescendantsAndSelf("link");
     if (matches.Any())
     {
         return matches.First().Value;
     }
     return String.Empty;
 }
开发者ID:BO45,项目名称:NzbDrone,代码行数:9,代码来源:AnimezbParser.cs

示例11: ExtractElements

		public IEnumerable<XElement> ExtractElements(XElement ast) {
			foreach (var nameAndRules in FilterDictionary) {
				var elements = ast.DescendantsAndSelf(nameAndRules.Key);
				var rules = nameAndRules.Value;
				var results = elements.Where(e => rules.All(rule => rule.IsAcceptable(e)));
				foreach (var result in results) {
					yield return result;
				}
			}
		}
开发者ID:audioglider,项目名称:OpenCodeCoverageFramework,代码行数:10,代码来源:ExtractingRule.cs

示例12: GetSize

 protected override long GetSize(XElement item)
 {
     IEnumerable<XElement> matches = item.DescendantsAndSelf("enclosure");
     if (matches.Any())
     {
         XElement enclosureElement = matches.First();
         return Convert.ToInt64(enclosureElement.Attribute("length").Value);
     }
     return 0;
 }
开发者ID:BO45,项目名称:NzbDrone,代码行数:10,代码来源:AnimezbParser.cs

示例13: File

 public static string File(string id, XElement xaml, string type = null, string path = null)
 {
     var e = xaml.DescendantsAndSelf(xic + id).FirstOrDefault();
     if (e != null) {
         if (e.Attribute(xic+"ImageType") != null) type = (string)e.Attribute(xic+"ImageType");
         if (e.Attribute(xic+"Cache") != null) path = (string)e.Attribute(xic+"Cache");
     }
     path = path ?? Path;
     if (type == null) type = "png";
     if (!path.EndsWith("/")) path += "/";
     return path + id + "." + Hash.Compute(xaml).ToString() + "." + type;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:12,代码来源:XamlImageConverterLazyHandler.cs

示例14: BuildWiki

		private void BuildWiki(StringBuilder sb, XElement e){
			haserrors = false;
			int nscnt = 1;
			var namespaces = new Dictionary<string, string>();

			foreach (XElement element in e.DescendantsAndSelf()){
				if (!string.IsNullOrWhiteSpace(element.Name.NamespaceName)){
					if (element.Name.NamespaceName == "http://www.w3.org/2000/xmlns/") continue;
					if (!namespaces.ContainsKey(element.Name.NamespaceName)){
						namespaces[element.Name.NamespaceName] = "ns" + nscnt++;
					}
				}
				foreach (XAttribute attr in element.Attributes()){
					if (!string.IsNullOrWhiteSpace(attr.Name.NamespaceName)){
						if (attr.Name.NamespaceName == "http://www.w3.org/2000/xmlns/") continue;
						if (!namespaces.ContainsKey(attr.Name.NamespaceName)){
							namespaces[attr.Name.NamespaceName] = "ns" + nscnt++;
						}
					}
				}
			}
			sb.AppendLine("<div class='wk-x'>");
			if (!_showroot){
				if (namespaces.Count != 0){
					sb.AppendLine(
						"&lt;!-- документы XML полученные из BXL/B# выводятся (в WIKI) не от корня, справка по пространствам имен:");
					sb.AppendLine("<br/>");
					foreach (var ns in namespaces){
						sb.AppendLine(ns.Value + " :: " + ns.Key);
						sb.AppendLine("<br/>");
					}
					sb.AppendLine("-->");
					sb.AppendLine("<br/>");
				}
			}
			if (_showroot){
				BuildWiki(sb, e, 0, namespaces);
			}
			else{
				foreach (XElement element in e.Elements()){
					BuildWiki(sb, element, 0, namespaces);
				}
			}
			sb.AppendLine("</div>");
			if (haserrors){
				sb.AppendLine("<div class='wk-x-error'>");
				foreach (XElement element in e.Elements()){
					if (element.Name.LocalName != "bx-error") continue;
					Append(sb, element.Value, "wk-x-error-" + element.Attr("level"), tagname: "div");
				}
				sb.AppendLine("</div>");
			}
		}
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:53,代码来源:SmartXmlHandler.cs

示例15: AnalyzeFirstLineNumberOrDefault

 public static int AnalyzeFirstLineNumberOrDefault(XElement elem)
 {
     foreach (var e in elem.DescendantsAndSelf()) {
         if (IgnoredElements.Contains(e.Name())) {
             continue;
         }
         var attr = e.Attribute("startline");
         if (attr != null) {
             return int.Parse(attr.Value);
         }
     }
     return 0;
 }
开发者ID:exKAZUu,项目名称:TransformerGenerator,代码行数:13,代码来源:Analyzer.cs


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