开发者

reading xml facebook file in ASP.NET

开发者 https://www.devze.com 2023-03-23 07:52 出处:网络
I\'m trying to read a xml file (from facebook) into my page. I keep getting an error. Can\'t figure it out.

I'm trying to read a xml file (from facebook) into my page. I keep getting an error. Can't figure it out.

Dim ds As New DataSet
Dim myURL As String = "http://www.facebook.com/feeds/page.php?id=68310606562&format=rss20"

ds.ReadXml(myURL)

This throws an exception:

An error occurred while parsing Enti开发者_高级运维tyName. Line 12, position 53.

Any thoughts? Thanks!


The contents of myURL is your URL, not an XML filename.

Try first making a request to retrieve this XML content via WebClient's DownloadString() method or similar method

var client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

var xmlData = client.DownloadString(url);


You can try the following:

XmlDocument doc = new XmlDocument();            
WebRequest req = WebRequest.Create("http://www.facebook.com/feeds/page.php?id=68310606562&format=rss20");
WebResponse resp = req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
string xml = reader.ReadToEnd();
doc.Load(xml);

You should be logged in to be able to retrieve the XML from Facebook.

0

精彩评论

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