Home All Groups Group Topic Archive Search About

Problem Reading XML from Website

Author
19 Nov 2007 7:55 PM
Scott McNair
Hi,

I'm trying to read a bit of XML from the following site:

http://www.wowarmory.com/character-sheet.xml?r=Bladefist&n=Coquette

The xml document relies heavily on xsl... however if you view the source of
the page you'll see that it is indeed raw xml that's being served.

I'm using the following code to pull the xml document in string format:

Public Shared Function GetPageAsString(ByVal address As Uri) As String
   Dim request As HttpWebRequest
   Dim response As HttpWebResponse = Nothing
   Dim reader As StreamReader
   Dim result As String

   Try
      request = DirectCast(WebRequest.Create(address), HttpWebRequest)
      response = DirectCast(request.GetResponse(), HttpWebResponse)
      reader = New StreamReader(response.GetResponseStream())
      result = reader.ReadToEnd()
   Finally
      If Not response Is Nothing Then response.Close()
   End Try
   Return result
End Function

However when I view the resulting string value, it shows the xsl-parsed
code.  How can I retrieve just the raw xml?

Regards,
Scott M.

Author
20 Nov 2007 12:05 PM
Martin Honnen
Scott McNair wrote:

Show quoteHide quote
> I'm trying to read a bit of XML from the following site:
>
> http://www.wowarmory.com/character-sheet.xml?r=Bladefist&n=Coquette
>
> The xml document relies heavily on xsl... however if you view the source of
> the page you'll see that it is indeed raw xml that's being served.
>
> I'm using the following code to pull the xml document in string format:
>
> Public Shared Function GetPageAsString(ByVal address As Uri) As String
>    Dim request As HttpWebRequest
>    Dim response As HttpWebResponse = Nothing
>    Dim reader As StreamReader
>    Dim result As String
>
>    Try
>       request = DirectCast(WebRequest.Create(address), HttpWebRequest)

   request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
>       response = DirectCast(request.GetResponse(), HttpWebResponse)
>       reader = New StreamReader(response.GetResponseStream())
>       result = reader.ReadToEnd()
>    Finally
>       If Not response Is Nothing Then response.Close()
>    End Try
>    Return result
> End Function
>
> However when I view the resulting string value, it shows the xsl-parsed
> code.  How can I retrieve just the raw xml?

Your code simply makes a HTTP GET request and reads the response. If you
get HTML then the server sends HTML. It seems to help to set the HTTP
UserAgent as shown above, then I get XML and not HTML.

--

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/