System.Xml.Linq命名空间

时间:2011-08-11 10:58:21

标签: asp.net vb.net linq-to-xml

我被赋予了调用Web服务的任务,该服务返回一个我正在这样做的xml数据源;

For Each r As DataRow in SomeDataTable
    Dim msFeed As String = string.format("http://some-feed.com?param={0}", r!SOME_VAL)
    Dim x As XDocument = XDocument.Load(msFeed)
Next

这一切都很好但是你可以看到x只是被每次迭代覆盖。我需要的是创建一个xDocument并从我的循环添加每个feed但我不确定如何继续。

由于

解决方案

Dim xAllFeeds As XElement = New XElement("Feeds")

For Each r As DataRow in SomeDataTable
    Dim msFeed As String = string.format("http://some-feed.com?param={0}", r!SOME_VAL)
    Dim x As XDocument = XDocument.Load(msFeed)
    xAllFeeds.Add(x.Root)
Next

1 个答案:

答案 0 :(得分:1)

不是100%确定VB语法(C#是我选择的语言),但这应该是你所追求的目标。

Dim xAllFeeds As XElement = New XElement("Feeds")
For Each r As DataRow in SomeDataTable
    Dim msFeed As String = string.format("http://some-feed.com?param={0}", r!SOME_VAL)
    Dim xDoc As XDocument = XDocument.Load(msFeed)
    xAllFeeds.Add(xDoc.Root)
Next