Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
i am trying to read xml data using c#,here ia m facing the issue is i am not able to read the data.
i am trying to implement getting yahoo stickers data from yahoo url and bind into table.
The data contains URL and read that data and bind to table.
i am using the below code
C#
string yahooURL = ConnectionStrings.yahooURL;
                       string symbolList = String.Join("%2C", Quotes.Select(w => "%22" + w.Symbol + "%22").ToArray());
                       string url = string.Format(yahooURL,symbolList);
                      XDocument doc = XDocument.Load(url);
                       XElement results = doc.Root.Element("results");
                       foreach (Quote quote in Quotes)
                       {
                           Watchlist objPC = new Watchlist();
                           XElement q = results.Elements("quote").First(w => w.Attribute("symbol").Value == quote.Symbol);
                           objPC.Symbol = quote.Symbol;
                           objPC.Name = q.Element("Name").Value;
                           objPC.Price = GetDecimal(q.Element("LastTradePriceOnly").Value);
                           objPC.Change = GetDecimal(q.Element("Change").Value);
                           objPC.ChangeInPercent = GetDecimal(q.Element("ChangeinPercent").Value);
                           objPC.Volume = GetDecimal(q.Element("Volume").Value);
                           objPC.DaysRange = q.Element("DaysRange").Value;
                           objPC.YearRange = q.Element("YearRange").Value;
                           objPC.MarketCapitalization = q.Element("MarketCapitalization").Value;
                           propClass.Add(objPC);
                       }



here i am getting the error is "
C#
'>' is an unexpected token. The expected token is '"' or '''. Line 1, position 50.

the below line i am getting the error
C#
XDocument doc = XDocument.Load(url);


Any Body can Please share solution to me.


this is the url
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22FLWS%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys[^]

What I have tried:

Here i am getting URL and that URL the xml data is coming,But i am not able to read the data.
Posted
Updated 27-Apr-16 1:00am
v3
Comments
phil.o 22-Apr-16 6:08am    
What is the value of the url variable when the exception is raised?
Ram349 22-Apr-16 6:18am    
this is the url
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22FLWS%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
phil.o 22-Apr-16 6:42am    
Apparently there is no yahoo.finance.quotes table to query; you can see that with their query tester: YQL Console.
Andy Lanng 22-Apr-16 6:55am    
@Phil.io: there is but this forum changes an '&' into '&'

It rendered in the comment but when you edit the comment to get the full string it shows '&'
Ram349 22-Apr-16 7:01am    
Hi Phil,
Thanks for replying to my post,I am getting the data but i am not able to read the data.Can u Please check the above URL

I'd guess the issue is the comments at the end.

.Net like XML structures to have a single root node (Excluding the XML header).

Yours has 3 root nodes because of the comments.
 
Share this answer
 
Comments
Richard Deeming 22-Apr-16 10:55am    
It doesn't have three root nodes; the XDocument class is quite happy with the document as-is.

It's more likely to be an issue with the URL. The server is probably returning an HTML error page, which can't be parsed as XML.
D-Kishore 25-Apr-16 1:09am    
It was working fine with same code last month. This issue came suddenly. Is there any need to update the XML DLL references to the project.
D-Kishore 26-Apr-16 23:56pm    
The below code works fine in .net desktop applications. But the same code not working in .net we applications. its throwing "'>' is an unexpected token. The expected token is '"' or '''. Line 1, position 50".

try
{


string URL = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22JPM%22%2C%22FLWS%22%2C%22FCTY%22%2C%22XXII%22%2C%22SRCE%22%2C%22FCCY%22%2C%22WUBA%22%2C%22DDD%22%2C%22AMRK%22%2C%22FLWS%22%2C%22FCTY%22)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
XDocument doc = XDocument.Load(URL);
}
catch(Exception ex)
{
}
Replace http with https. it works great
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900