Oh, now I get it. You don't need any source code to prove a point, because
it's nothing you're doing. Let me explain.
You are using this URL:
http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=MSFT
The response has a lot of instances of "<" in it.
But in Internet Explorer it looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<string
xmlns="http://www.webserviceX.NET/"><StockQuotes><Stock><Symbol>MSFT</Symbol
<Last>29.77</Last><Date>11/9/2004</Date><Time>3:59pm</Time><Change>+0.49</C
hange><Open>29.43</Open><High>29.89</High><Low>29.35</Low><Volume>96263152</
Volume><MktCap>323.5B</MktCap><PreviousClose>29.28</PreviousClose><Percentag
eChange>+1.67%</PercentageChange><AnnRange>24.01 -
29.89</AnnRange><Earns>0.78</Earns><P-E>37.54</P-E><Name>MICROSOFT
CP</Name></Stock></StockQuotes></string>
That's because Internet Explorer is parsing the XML and decoding the < to
<.
You too need to parse the XML, for which you will need an XML parser. MSXML
is a free one available from Microsoft and included in recent versions of
Internet Explorer and Windows.
Paul
#include <windows.h>
#include <wininet.h>
#include <stdio.h>
void main()
{
FILE *fp = fopen("c:\\test.txt", "a");
if (!fp)
return;
BOOL InetCanConnect = FALSE;
HINTERNET hiOpen = NULL;
HINTERNET hiFile = NULL;
TCHAR webData[1024];
DWORD dwRead;
if (ERROR_SUCCESS != InternetAttemptConnect(0))
goto end;
if (NULL == (hiOpen = InternetOpen("TestApp",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0x0)))
goto end;
if (NULL != (hiFile = InternetOpenUrl(hiOpen,
"http://www.webservicex.net/RealTimeMarketData.asmx/Quote?Symbol=MSFT",
NULL, 0, 0, 0)))
{
InternetReadFile(hiFile, webData, 1023, &dwRead);
InternetCloseHandle(hiFile);
webData[dwRead] = 0;
fprintf(fp, "%s\n", webData);
}
if (NULL != (hiFile = InternetOpenUrl(hiOpen,
"http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=MSFT",
NULL, 0, 0, 0)))
{
InternetReadFile(hiFile, webData, 1023, &dwRead);
InternetCloseHandle(hiFile);
webData[dwRead] = 0;
fprintf(fp, "%s\n", webData);
}
InternetCloseHandle(hiOpen);
fclose(fp);
}
<?xml version="1.0" encoding="utf-8"?>
<QuoteList xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.webservicex.net/">
<QuoteLists>
<Quote>
<Symbol>MSFT</Symbol>
<DateTime>19:59:57.416-05:00</DateTime>
<MatchedShares>17563379</MatchedShares>
<Price>29.34</Price>
</Quote>
</QuoteLists>
</QuoteList>
<?xml version="1.0" encoding="utf-8"?>
<string
-
29.89</AnnRange><Earns>0.78</Earns><P-E>37.58</P-
E><Name>MICROSOFT
James
Post by Paul Baker [MVP, Windows - SDK]James,
Please give specific examples. I tried both and I saw nothing odd.
Paul
Post by James PWhen I call http://www.webservicex.net/RealTimeMarketData.asmx the output
xml does not contain < etc.
When I call http://www.webservicex.net/stockquote.asmx the output xml has
these characters.
When I open it in IE, everything looks ok.
Any idea why and how I can get the output without those characters?
Thanks.
James
http://www.poovathummoottil.com