none
Read XML from WebPages RRS feed

  • Question

  •  

    Hi all,

             I am reading the contents of a web page using this method

     

    Code Snippet

    Dim xmlhttp As New MSXML2.XMLHTTP30

    xmlhttp.open("GET", strUrl, False)

    xmlhttp.send()

    MsgBox(xmlhttp.responseText)

     

     

    This displayed the view source of the of the wep page. I tried to load the file in XMLDOM object

     

    Code Snippet
     Message "'?', hexadecimal value 0xFFFF, is an invalid character. Line 15, position 42." String

     

     


    How to solve this issue.

     

    The sample contents of the xmlhttp.response.Text

    Code Snippet

    <AbsencesType ID="103" Name="Thuiswerken standaard"></AbsencesType>

    <AbsencesType ID="172" Name="To Do"></AbsencesType>

    <AbsencesType ID="3" Name="T?."></AbsencesType>

    <AbsencesType ID="125" Name="USG at Almere"></AbsencesType>

     

     

     

    Thanks in Advance

    Dana

    Wednesday, February 13, 2008 12:35 PM

Answers

  • Hi, have you tried using the webrequest method?

    I had something similar which I would request an address through the web and the response would be in XML. I would require to capture the content where i can read it from using the application. Here is the method from MSDN Library (Webrequest Class):


    Code Snippet

    Imports System
    Imports
    System.IO
    Imports System.Net
    Imports System.Text
    Namespace Examples.System.Net
    Public Class WebRequestGetExample

    Public Shared Sub Main()
    ' Create a request for the URL.
    Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html")
    ' If required by the server, set the credentials.
    request.Credentials = CredentialCache.DefaultCredentials
    ' Get the response.
    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    ' Display the status.
    Console.WriteLine(response.StatusDescription)
    ' Get the stream containing content returned by the server.
    Dim dataStream As Stream = response.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.
    Dim reader As New StreamReader(dataStream)
    ' Read the content.
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.
    Console.WriteLine(responseFromServer)
    ' Cleanup the streams and the response.
    reader.Close()
    dataStream.Close()
    response.Close()
    End Sub 'Main
    End Class 'WebRequestGetExample
    End Namespace


    And the link for the site: 
    http://msdn2.microsoft.com/en-us/library/system.net.webrequest.aspx

    Hope it helps. Hope its what you are looking for Smile

    Good Luck
    Karim


    Thursday, February 14, 2008 11:01 AM

All replies

  • Is that VB.NET code? You should not use MSXML with VB.NET: http://support.microsoft.com/kb/815112/en-us

    The .NET framework has its own classes in System.Xml for XML parsing so with the .NET framework you could simply do

    Code Snippet

    Dim doc As New XmlDocument()

    Try

      doc.Load(strUrl)

    Catch e As XmlException

      ' handle parse error here

    End Try

     

     

    If you still have problems then post the URL you are trying to read the XML from.
    Wednesday, February 13, 2008 1:23 PM
  • Thanks for the post Martin.
     
       I tried like this

    Code Snippet
    Dim doc As XmlDocument = New XmlDocument
    doc.XmlResolver = xmlresol

     

     

    And got the error as

    Code Snippet
    The remote server returned an error: (401) Unauthorized+xmldocument.load

     

     


    Then I tried this one

     

    Code Snippet
    Dim xmlresol As XmlUrlResolver = New XmlUrlResolver
     xmlresol.Credentials = System.Net.CredentialCache.DefaultCredentials
     Dim doc As XmlDocument = New XmlDocument
     doc.XmlResolver = xmlresol
     doc.Load(strUrl)

     

     

    And got the same errror again.


    It is a local wep page I am tryig to get the view source of that page
    That page has the "WINDOWS Authentication Mode". If a user
    call with no right to that page then that page then he has
    to supply the username and password.

     

    After supplying the username and pwd that asp page will produce
    will write xml content in the body. I am trying to get
    that content. Hope I am clear

     

    Thanks
    Dana

    Thursday, February 14, 2008 5:51 AM
  • Hi, have you tried using the webrequest method?

    I had something similar which I would request an address through the web and the response would be in XML. I would require to capture the content where i can read it from using the application. Here is the method from MSDN Library (Webrequest Class):


    Code Snippet

    Imports System
    Imports
    System.IO
    Imports System.Net
    Imports System.Text
    Namespace Examples.System.Net
    Public Class WebRequestGetExample

    Public Shared Sub Main()
    ' Create a request for the URL.
    Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html")
    ' If required by the server, set the credentials.
    request.Credentials = CredentialCache.DefaultCredentials
    ' Get the response.
    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    ' Display the status.
    Console.WriteLine(response.StatusDescription)
    ' Get the stream containing content returned by the server.
    Dim dataStream As Stream = response.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.
    Dim reader As New StreamReader(dataStream)
    ' Read the content.
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.
    Console.WriteLine(responseFromServer)
    ' Cleanup the streams and the response.
    reader.Close()
    dataStream.Close()
    response.Close()
    End Sub 'Main
    End Class 'WebRequestGetExample
    End Namespace


    And the link for the site: 
    http://msdn2.microsoft.com/en-us/library/system.net.webrequest.aspx

    Hope it helps. Hope its what you are looking for Smile

    Good Luck
    Karim


    Thursday, February 14, 2008 11:01 AM