Home All Groups Group Topic Archive Search About

How to read XML data stream via a URL address into a string ?

Author
25 Feb 2009 4:21 PM
fniles
I know how to read XML from a file.
But I will need to load the XML content from a URL, so when I go to the URL,
the result is XML file, and I will need to capture the content to a string.
How can I do that ?
Thank you.

Author
25 Feb 2009 5:20 PM
Jeff Johnson
"fniles" <fni***@pfmail.com> wrote in message
news:eYMaSU2lJHA.1292@TK2MSFTNGP02.phx.gbl...

>I know how to read XML from a file.
> But I will need to load the XML content from a URL, so when I go to the
> URL,
> the result is XML file, and I will need to capture the content to a
> string.
> How can I do that ?

Set a reference to one of the Microsoft XML xxx libraries (preferably the
newest you have) and then look at the XMLHTTPxx classes. They have to
ability to send requests, i.e., get data from a URL, and then they'll have
the result in one or more of their responsexxx properties.
Author
26 Feb 2009 2:28 AM
Bill McCarthy
If you have the xml in a string you can use the DOMDocument's LoadXML
method.

Show quoteHide quote
"fniles" <fni***@pfmail.com> wrote in message
news:eYMaSU2lJHA.1292@TK2MSFTNGP02.phx.gbl...
>I know how to read XML from a file.
> But I will need to load the XML content from a URL, so when I go to the
> URL,
> the result is XML file, and I will need to capture the content to a
> string.
> How can I do that ?
> Thank you.
>
>
Author
26 Feb 2009 2:41 PM
Jeff Johnson
"Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
news:OXUM0p7lJHA.4420@TK2MSFTNGP05.phx.gbl...

> If you have the xml in a string you can use the DOMDocument's LoadXML
> method.

He doesn't have the XML. The question, as I understood it, was "How do I get
XML from a Web request?"
Author
26 Feb 2009 11:19 PM
Bill McCarthy
"Jeff Johnson" <i.get@enough.spam> wrote in message
news:ua5MdBCmJHA.1172@TK2MSFTNGP04.phx.gbl...
> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
> news:OXUM0p7lJHA.4420@TK2MSFTNGP05.phx.gbl...
>
>> If you have the xml in a string you can use the DOMDocument's LoadXML
>> method.
>
> He doesn't have the XML. The question, as I understood it, was "How do I
> get XML from a Web request?"

Ah, yep I think you're right.  I think for that I'd favor using the
AsyncRead of a usercontrol class for simple urls, switching to the XMLHTTPnn
classes if he needs to send extra header info.  The usercontrol makes doing
an async read easy/event based; whereas the XMLHTTPnn classes don't have
events so you have to poll it's state if doing async.
Author
27 Feb 2009 2:30 PM
fniles
Thank you for your replies.

To clarify:
The XML data comes in a data stream, instead of in a file.
We need to access an XML data stream via a URL address. We want to capture
the content of the stream to a string.

Show quoteHide quote
"Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
news:%23R8QAjGmJHA.504@TK2MSFTNGP06.phx.gbl...
>
> "Jeff Johnson" <i.get@enough.spam> wrote in message
> news:ua5MdBCmJHA.1172@TK2MSFTNGP04.phx.gbl...
>> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
>> news:OXUM0p7lJHA.4420@TK2MSFTNGP05.phx.gbl...
>>
>>> If you have the xml in a string you can use the DOMDocument's LoadXML
>>> method.
>>
>> He doesn't have the XML. The question, as I understood it, was "How do I
>> get XML from a Web request?"
>
> Ah, yep I think you're right.  I think for that I'd favor using the
> AsyncRead of a usercontrol class for simple urls, switching to the
> XMLHTTPnn classes if he needs to send extra header info.  The usercontrol
> makes doing an async read easy/event based; whereas the XMLHTTPnn classes
> don't have events so you have to poll it's state if doing async.
Author
27 Feb 2009 3:24 PM
mayayana
>
> To clarify:
> The XML data comes in a data stream, instead of in a file.
> We need to access an XML data stream via a URL address. We want to capture
> the content of the stream to a string.
>

  their answers are telling you ways to download the file.
Once you've got it, it's easy enough to convert that to
a string. The method that Bill McCarthy couldn't be
bothered to explain usefully is detailed here:

http://vb.mvps.org/samples/project.asp?id=netgrab

For the XML method you might get better help in:

microsoft.public.scripting.vbscript

  There are various XML object model libraries on
Windows. The versions present vary. You can use
those to download files. But the XML libraries are
mainly high-level scripting tools.

  If you want to perform and control the download
yourself, without needing external tools, see here
for a sample that carries out the conversation with
the server directly:

www.jsware.net/jsware/vbcode.php5#htp

  And there are also Wininet functions for downloading,
which basically wrap IE functionality.

  Of all of the above, Karl Peterson's "NetGrab" may be
the easiest.

  Presumably you already know what you're doing once you
get the XML string. If not, your choices are pretty much
down to either simple parsing or using one of the XML
libraries to translate the text into an XML object model.
(As with HTML, you can either just parse it or load it into
IE and deal with the document object.)
  For the XML object model, again, you might find more help
in the vbscript group.