本文整理汇总了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);
}
}
}
示例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")));
}
}
示例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;
}
}
示例4: ReplaceFormTagByDivTag
internal static void ReplaceFormTagByDivTag(XElement document)
{
foreach (var form in document.DescendantsAndSelf(ns + "form"))
{
form.Name = ns + "div";
}
}
示例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;
}
示例6: Parse
public LastfmResponse<LastfmUserItem> Parse(XElement xmlResponse)
{
lfmNodeErrorParser.Parse(xmlResponse);
var tracks = xmlResponse.DescendantsAndSelf(CollectionElementName);
var tracksElement = tracks.First();
return CreateUserItem(tracksElement);
}
示例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;
}
示例8: Parse
public LastfmResponse<LastfmLibraryItem> Parse(XElement xmlResponse)
{
lfmNodeErrorParser.Parse(xmlResponse);
var collection = xmlResponse.DescendantsAndSelf(CollectionElementName);
var collectionElement = collection.First();
return CreateLibraryItem(collectionElement);
}
示例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);
}
}
}
示例10: GetNzbInfoUrl
protected override string GetNzbInfoUrl(XElement item)
{
IEnumerable<XElement> matches = item.DescendantsAndSelf("link");
if (matches.Any())
{
return matches.First().Value;
}
return String.Empty;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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(
"<!-- документы 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>");
}
}
示例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;
}