鉴于此URL:
http://www.dreamincode.net/forums/xml.php?showuser=1253
如何下载生成的XML文件并将其加载到内存中以便我可以使用Linq从中获取信息?
谢谢您的帮助.
Gab*_*abe 40
为什么复杂的事情?这有效:
var xml = XDocument.Load("http://www.dreamincode.net/forums/xml.php?showuser=1253");
Run Code Online (Sandbox Code Playgroud)
Eli*_*sha 24
加载字符串:
string xml = new WebClient().DownloadString(url);
Run Code Online (Sandbox Code Playgroud)
然后加载到XML:
XDocument doc = XDocument.Parse(xml);
Run Code Online (Sandbox Code Playgroud)
例如:
[Test]
public void TestSample()
{
string url = "http://www.dreamincode.net/forums/xml.php?showuser=1253";
string xml;
using (var webClient = new WebClient())
{
xml = webClient.DownloadString(url);
}
XDocument doc = XDocument.Parse(xml);
// in the result profile with id name is 'Nate'
string name = doc.XPathSelectElement("/ipb/profile[id='1253']/name").Value;
Assert.That(name, Is.EqualTo("Nate"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31064 次 |
| 最近记录: |