开发者

System.Xml.Linq Namespace

I have been given the task of calling a web service which returns an xml data feed which I am doing like so;

F开发者_JS百科or 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

This is all fine but as you can see x just gets overwritten with every iteration. What I need is create an xDocument and add each feed from my loop but I am unsure how to proceed.

Thanks

Solution

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


Not 100% sure of the VB syntax (C# is my language of choice), but this should be the gist of what you're after.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜