System.Xml.Linq 命名空间
我的任务是调用一个 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 并添加循环中的每个提要,但我不确定如何继续。
谢谢
解决方案
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是 100% 确定 VB 语法(C# 是我选择的语言),但这应该是您所追求的要点。
Not 100% sure of the VB syntax (C# is my language of choice), but this should be the gist of what you're after.