简体   繁体   English

我如何只获取节点名称而不是名称空间

[英]How can i get name of the node only not the namespace

I have this node: . 我有这个节点:。 I am using LINQ query to get this node. 我正在使用LINQ查询来获取此节点。 How can i get this node but not the namespace? 我如何获得此节点,但不能获得名称空间? I tried using: 我尝试使用:

foreach(var g in xDoc.Descendants(ab + "games"){

         g.Name.ToString();
}

This gives ab(whole namespace string) also with the name. 这也给ab(整个名称空间字符串)加上名称。 Is there a easier way to remove this? 有没有更简单的方法来删除此?

使用XElement.Name.LocalName属性。

You can do it using the LocalName property: 您可以使用LocalName属性来实现:

foreach(var g in xDoc.Descendants(ab + "games"){
     g.Name.LocalName;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取具有命名空间和类名的方法名称? - How can I get a method name with the namespace & class name? 如何在C#中动态获取NameSpace和Class的名称? - How can I get the name of NameSpace and Class dynamically in C#? 如何使用类似节点名称的XmlDocument获取XmlNodes数据? - how can I get XmlNodes data with XmlDocument in similar node name? 如何使用 Roslyn 在给定的命名空间上下文中获取任意类型的最完全简化的类型名称? - How can I get the most fully reduced type name of an arbitrary type in a given namespace context using Roslyn? 如何获取命名空间中的所有控件? - How can I get all the controls in a namespace? 如何使公司名称进入命名空间? - How to get the company name into the namespace? 如何仅使用系统名称空间扩展RichTextBox控件 - How can I extend the richtextbox control using system namespace only 我可以在不知道dll文件名的情况下加载程序集,其中我只知道命名空间名称 - Can I load an Assembly without knowing the dll filename, where I only know the namespace name 如何从目录字符串中仅获取最后的子目录名称和文件名? - How can i get from a directory string only the last subdirectory name and the file name? 如何从泛型类型中获取命名空间? - How can I get the namespace from a generic type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM