1
我已经被赋予调用一个Web服务的任务,该服务返回一个xml数据提要,我正在这样做;System.Xml.Linq命名空间
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并从我的循环添加每个提要,但我不确定如何继续。
感谢
解决方案
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
感谢,而不是 '使用appendChild' 我只是用 '添加' – Dooie
对不起,这不是'AppendChild',只是'Add'(http://msdn.microsoft.com/en-us/library/system .xml.linq.xelement.aspx)。我已经适当调整了答案。 –