【发布时间】:2024-05-04 18:20:04
【问题描述】:
Dim names() As String = {"one", "two", "three"}
Dim xml As XElement = Nothing
For Each name In names
If xml Is Nothing Then
xml = New XElement(name)
Else
xml.Add(New XElement(name)
End If
Next
上面的代码将创建如下内容:
<One>
<Two />
<Three />
</One>
我需要的是这样的:
<One>
<Two>
<Three />
</Two>
</One>
我尝试使用 xml.Elements.Last.Add(New XElement(name)),但由于某种原因,Last 方法不一定会返回最后一个元素。
谢谢!
【问题讨论】:
标签: .net xml linq-to-xml