1

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

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

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, rather than 'AppendChild' i just used 'Add'
Sorry, It's not AppendChild, just Add (msdn.microsoft.com/en-us/library/system.xml.linq.xelement.aspx). I've adjusted the answer approriately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.