Retrieving data from a XML file on the web 
Author Message
 Retrieving data from a XML file on the web

I don't need to save the XML file, just retrieving some values from it,
what's the best way to do it in VC6?  Thanks.


Sun, 13 Nov 2005 19:22:16 GMT  
 Retrieving data from a XML file on the web
I don't need to save the XML file, just retrieving some values from it,
what's the best way to do it in VC6?  Thanks.


Sun, 13 Nov 2005 19:30:12 GMT  
 Retrieving data from a XML file on the web
I don't need to save the XML file, just retrieving some values from it,
what's the best way to do it in VC6?  Thanks.


Sun, 13 Nov 2005 19:55:07 GMT  
 Retrieving data from a XML file on the web
I don't need to save the XML file, just retrieving some values from it,
what's the best way to do it in VC6?  Thanks.


Sun, 13 Nov 2005 19:56:24 GMT  
 Retrieving data from a XML file on the web
Sorry guys, my ISP's news server is playing up.  The duplicated postings
aren't intentional.


Quote:
> I don't need to save the XML file, just retrieving some values from it,
> what's the best way to do it in VC6?  Thanks.



Sun, 13 Nov 2005 20:07:01 GMT  
 Retrieving data from a XML file on the web

Quote:

> I don't need to save the XML file, just retrieving some values from
> it, what's the best way to do it in VC6?  Thanks.

Use MSXML, in particular the XmlHttp object.   Look it up on MSDN.

-cd



Sun, 13 Nov 2005 21:18:07 GMT  
 Retrieving data from a XML file on the web
Thanks, I pull the following example from MSDN into a dialog based app for a
quick test...

#import "msxml3.dll"
using namespace MSXML2;

void XMLHttpRequestSample()
{
   IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
   BSTR bstrString = NULL;
   HRESULT hr;

   try {
      hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP");
      SUCCEEDED(hr) ? 0 : throw hr;

      hr=pIXMLHTTPRequest->open("GET",
"http://XMLSampleServer/CatalogServer.asp", false);
      SUCCEEDED(hr) ? 0 : throw hr;

      hr=pIXMLHTTPRequest->send();
      SUCCEEDED(hr) ? 0 : throw hr;

      bstrString=pIXMLHTTPRequest->responseText;

      MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);

      if(bstrString)
      {
         ::SysFreeString(bstrString);
         bstrString = NULL;
      }

   } catch (...) {
      MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
      if(bstrString)
         ::SysFreeString(bstrString);
   }

Quote:
}

The code failed at CreateInstance, it thrown "exception occured" error which
I have no idea on what's going on?  Do you know what's wrong?



Quote:

> > I don't need to save the XML file, just retrieving some values from
> > it, what's the best way to do it in VC6?  Thanks.

> Use MSXML, in particular the XmlHttp object.   Look it up on MSDN.

> -cd



Sun, 13 Nov 2005 23:14:40 GMT  
 Retrieving data from a XML file on the web
Did you remember to call CoInitialize()?
-cd
Quote:

> Thanks, I pull the following example from MSDN into a dialog based
> app for a quick test...

> #import "msxml3.dll"
> using namespace MSXML2;

> void XMLHttpRequestSample()
> {
>    IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
>    BSTR bstrString = NULL;
>    HRESULT hr;

>    try {
>       hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP");
>       SUCCEEDED(hr) ? 0 : throw hr;

>       hr=pIXMLHTTPRequest->open("GET",
> "http://XMLSampleServer/CatalogServer.asp", false);
>       SUCCEEDED(hr) ? 0 : throw hr;

>       hr=pIXMLHTTPRequest->send();
>       SUCCEEDED(hr) ? 0 : throw hr;

>       bstrString=pIXMLHTTPRequest->responseText;

>       MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);

>       if(bstrString)
>       {
>          ::SysFreeString(bstrString);
>          bstrString = NULL;
>       }

>    } catch (...) {
>       MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
>       if(bstrString)
>          ::SysFreeString(bstrString);
>    }

> }

> The code failed at CreateInstance, it thrown "exception occured"
> error which I have no idea on what's going on?  Do you know what's
> wrong?




>>> I don't need to save the XML file, just retrieving some values from
>>> it, what's the best way to do it in VC6?  Thanks.

>> Use MSXML, in particular the XmlHttp object.   Look it up on MSDN.

>> -cd



Sun, 13 Nov 2005 23:29:52 GMT  
 Retrieving data from a XML file on the web
That's it, CoInitialize solved the problem.

IXMLHTTPRequest works most of the time, however, it hangs at the send()
method for certain files and I don't have a clue what's wrong, any ideas?



Quote:
> Did you remember to call CoInitialize()?
> -cd


> > Thanks, I pull the following example from MSDN into a dialog based
> > app for a quick test...

> > #import "msxml3.dll"
> > using namespace MSXML2;

> > void XMLHttpRequestSample()
> > {
> >    IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
> >    BSTR bstrString = NULL;
> >    HRESULT hr;

> >    try {
> >       hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP");
> >       SUCCEEDED(hr) ? 0 : throw hr;

> >       hr=pIXMLHTTPRequest->open("GET",
> > "http://XMLSampleServer/CatalogServer.asp", false);
> >       SUCCEEDED(hr) ? 0 : throw hr;

> >       hr=pIXMLHTTPRequest->send();
> >       SUCCEEDED(hr) ? 0 : throw hr;

> >       bstrString=pIXMLHTTPRequest->responseText;

> >       MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);

> >       if(bstrString)
> >       {
> >          ::SysFreeString(bstrString);
> >          bstrString = NULL;
> >       }

> >    } catch (...) {
> >       MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
> >       if(bstrString)
> >          ::SysFreeString(bstrString);
> >    }

> > }

> > The code failed at CreateInstance, it thrown "exception occured"
> > error which I have no idea on what's going on?  Do you know what's
> > wrong?




> >>> I don't need to save the XML file, just retrieving some values from
> >>> it, what's the best way to do it in VC6?  Thanks.

> >> Use MSXML, in particular the XmlHttp object.   Look it up on MSDN.

> >> -cd



Mon, 14 Nov 2005 21:01:45 GMT  
 Retrieving data from a XML file on the web
That's it, CoInitialize solved the problem.

IXMLHTTPRequest works most of the time, however, it hangs at the send()
method for certain files and I don't have a clue what's wrong, any ideas?



Quote:
> Did you remember to call CoInitialize()?
> -cd


> > Thanks, I pull the following example from MSDN into a dialog based
> > app for a quick test...

> > #import "msxml3.dll"
> > using namespace MSXML2;

> > void XMLHttpRequestSample()
> > {
> >    IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
> >    BSTR bstrString = NULL;
> >    HRESULT hr;

> >    try {
> >       hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP");
> >       SUCCEEDED(hr) ? 0 : throw hr;

> >       hr=pIXMLHTTPRequest->open("GET",
> > "http://XMLSampleServer/CatalogServer.asp", false);
> >       SUCCEEDED(hr) ? 0 : throw hr;

> >       hr=pIXMLHTTPRequest->send();
> >       SUCCEEDED(hr) ? 0 : throw hr;

> >       bstrString=pIXMLHTTPRequest->responseText;

> >       MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);

> >       if(bstrString)
> >       {
> >          ::SysFreeString(bstrString);
> >          bstrString = NULL;
> >       }

> >    } catch (...) {
> >       MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
> >       if(bstrString)
> >          ::SysFreeString(bstrString);
> >    }

> > }

> > The code failed at CreateInstance, it thrown "exception occured"
> > error which I have no idea on what's going on?  Do you know what's
> > wrong?




> >>> I don't need to save the XML file, just retrieving some values from
> >>> it, what's the best way to do it in VC6?  Thanks.

> >> Use MSXML, in particular the XmlHttp object.   Look it up on MSDN.

> >> -cd



Mon, 14 Nov 2005 21:03:32 GMT  
 Retrieving data from a XML file on the web
If it hangs, it's most likely because the external web server is not
responding.  You might be able to determine what's happening by enabling
WinInet logging (xmlhttp uses wininet under the covers).

I'm looking for a reference page on WinInet logging - if I find one, I'll
post it.

-cd

Quote:

> That's it, CoInitialize solved the problem.

> IXMLHTTPRequest works most of the time, however, it hangs at the
> send() method for certain files and I don't have a clue what's wrong,
> any ideas?



Mon, 14 Nov 2005 21:30:15 GMT  
 Retrieving data from a XML file on the web
Thanks.

The strange thing is that I can access the exact same file via IE, but not
IXMLHTTPRequest.  By the way, that page requires authentication, I've tried
the following:


nothing happens (hang)

2) pIXMLHTTPRequest->open("GET", "url", false, "user", "password)
nothing happens (hang)

3) pIXMLHTTPRequest->open("POST", "url", false, "user", "password)
nothing happens (hang), but if wrong password, then it return authorization
error then hang.

4) pIXMLHTTPRequest->open("POST", "url", false, "user", "password)
nothing happens (hang), but if wrong password, then it return authorization
error then hang.

Thanks again for your help.



Quote:
> If it hangs, it's most likely because the external web server is not
> responding.  You might be able to determine what's happening by enabling
> WinInet logging (xmlhttp uses wininet under the covers).

> I'm looking for a reference page on WinInet logging - if I find one, I'll
> post it.

> -cd


> > That's it, CoInitialize solved the problem.

> > IXMLHTTPRequest works most of the time, however, it hangs at the
> > send() method for certain files and I don't have a clue what's wrong,
> > any ideas?



Tue, 15 Nov 2005 17:50:38 GMT  
 Retrieving data from a XML file on the web

--------------------

Quote:

>Subject: Retrieving data from a XML file on the web

>I don't need to save the XML file, just retrieving some values from it,
>what's the best way to do it in VC6?  Thanks.

Here is an example on how to load an XML document using its URL

HRESULT hr;
IXMLDOMDocument2 * pXMLDoc = NULL;
BSTR bstrFilename(<type your URL>);

hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument2, (void**)&pXMLDoc);

VARIANT vInput;
VARIANT_BOOL fSuccess;

V_VT(&vInput) = VT_BSTR;
V_BSTR(&vInput) = bstrFilename;

hr = pXMLDoc->put_async(VARIANT_FALSE);
hr = pXMLDoc->load(vInput, &fSuccess);

Please note that you need to check for return values/hr. For more details, please refer to DOMDocument help.
--
Samer Boshra, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm



Sun, 04 Dec 2005 02:36:43 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. VC++ and XML, I want to retrieve an XML file from URL

2. VC++ and XML, I want to retrieve an XML file from a URL

3. retrieve XML data from SQL server by using XSD mapping schema

4. how to retrieve records from an XML file

5. how to retrieve records from an XML file?

6. Retrieving a file from a web site

7. retrieve data from excel files

8. retrieve data from excel files

9. Retrieving data from excel file.

10. ___ RETRIEVE DATA FROM MS OUTLOOK FILES??? ___

11. Storing data from a datagrid into an XML file

12. Writing encrypted data into a XML file

 

 
Powered by phpBB® Forum Software