i am trying to retrieve the content from twitter username but i think something is failing in my code, probably incorrect xml code but i am not sure how to resolve this. the exact error is: (XML unhandled exception) - An error occurred while parsing EntityName.
Line 46, position 76.
public Collection<TwitterStatus> GetLatestMessages(long userId, int count, bool anchorLinks)
{
count = count > 200 ? 200 : (count < 1 ? 1 : count);
var xmlUrl = new Uri(string.Format(_culture, "http://api.twitter.com/1/statuses/user_timeline/user_id={0} count={1}", userId, count));
return GetLatestMessages(xmlUrl, anchorLinks);
}
private Collection<TwitterStatus> GetLatestMessages(Uri twitterUrl, bool anchorLinks)
{
//call the twitter url
using (var response = WebRequest.Create(twitterUrl).GetResponse())
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
settings.CheckCharacters = false;
//load the xml response from twitter
using (var xr = XmlReader.Create(response.GetResponseStream(), settings))
{
xr.MoveToContent();
var xml = XDocument.Load(xr);//ERROR
dm007
Member
47 Points
106 Posts
error in code - while parsing entity name
Nov 06, 2012 02:06 PM|LINK
i am trying to retrieve the content from twitter username but i think something is failing in my code, probably incorrect xml code but i am not sure how to resolve this. the exact error is: (XML unhandled exception) - An error occurred while parsing EntityName. Line 46, position 76.
public Collection<TwitterStatus> GetLatestMessages(long userId, int count, bool anchorLinks) { count = count > 200 ? 200 : (count < 1 ? 1 : count); var xmlUrl = new Uri(string.Format(_culture, "http://api.twitter.com/1/statuses/user_timeline/user_id={0} count={1}", userId, count)); return GetLatestMessages(xmlUrl, anchorLinks); } private Collection<TwitterStatus> GetLatestMessages(Uri twitterUrl, bool anchorLinks) { //call the twitter url using (var response = WebRequest.Create(twitterUrl).GetResponse()) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; settings.CheckCharacters = false; //load the xml response from twitter using (var xr = XmlReader.Create(response.GetResponseStream(), settings)) { xr.MoveToContent(); var xml = XDocument.Load(xr);//ERRORToughMan
Participant
1490 Points
635 Posts
Re: error in code - while parsing entity name
Nov 11, 2012 03:00 AM|LINK
Ur xml plz
RichardD
Contributor
3950 Points
549 Posts
Re: error in code - while parsing entity name
Nov 12, 2012 07:13 PM|LINK
Are you sure your URL is correct? Try "https://api.twitter.com/1/statuses/user_timeline/{0}.xml?count={1}" instead.