c# - 使用 XElement 在 C# 中获取最后一个元素

标签 c# xml xelement

我在 XElement 中加载了一个 XML 提要。

结构是

<root>
<post></post>
<post></post>
<post></post>
<post></post>
.
.
.
.
<post></post>
</root>

我想直接获取Last post的值。我如何在 C# 中使用 XElement 来做到这一点。

谢谢。

最佳答案

或者试试这个来获取 XElement:

XDocument doc = XDocument.Load("yourfile.xml");          
XElement root = doc.Root;
Console.WriteLine(root.Elements("post").Last());

关于c# - 使用 XElement 在 C# 中获取最后一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884804/

相关文章:

c# - ORM 的哪些选择允许接近 'flick a switch' 在...SQL Server/SQL Azure 和 PostgreSQL/'Cloud' PostgreSQL 之间更改 RDBMS

c# - 寻找开源项目 C#

xml - VB.NET XML Linq 获取后代

c# - 显式和隐式 XML namespace

c# - 将 "raw"XML 字符串插入 XElement

c# - 如何在 C# 中仅向 ref 元素添加命名空间?

c# - 具有属性的方法的 BindingFlags

c# - 在 Visual Studio for Mac 中添加 Web 引用

java - 线性布局发现意外的命名空间前缀 "xmlns"

c# - 来自 XElement 的内文?