Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2007

Tip: Looking for answers? Try searching our database.

Problems reading xml feed into XmlTextReader

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TheDude5B - 20 Sep 2007 10:26 GMT
hi,

I have a function which reads the xml from a web url into the
XmlTextReader, and then I work my way through the reader producing
html from the different nodes. All the code works fine when I debug
the project, but when I publish the project and run it on a live
server, I seem to be getting problems.

I get the error:

A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond

My code is as follows:

       Dim strURL As String = "http://www.nme.com/clubnmerss"
       Dim sb As New StringBuilder()
       Dim reader As New XmlTextReader(strURL)
       reader.MoveToContent()
       Dim sString2 As String = ""
       Dim hasEnteredGig As Integer = 0
       While reader.Read()
           If reader.Name = "venue" Then
               hasEnteredGig = 1
               sString = sString.Replace("##G##", sString2)
               sString2 = ""
               Venue = reader.ReadString()
               sString += "<div class='gig-box'><img src='media/liv/
club-nme.gif' /><br /></div>"
               sString += "<div class='gig'><div class='basic-
headline'><h1>CLUB NME</h1></div>##G##</div>"
               sString2 += "<h2>" & Venue & "</h2>"
           End If
           If reader.Name = "address" Then
               Address = reader.ReadString()
               sString2 += "<h2>" & Address & "</h2>"
           End If
           If reader.Name = "url" Then
               Url = reader.ReadString()
               sString2 += "<h2>" & Url & "</h2>"
           End If
           If reader.Name = "gig" Then
               Gig = reader.ReadString() & "<br />"
               sString2 += "" & Gig & ""
               hasEnteredGig = 0
           End If
       End While
       If hasEnteredGig = 0 Then
           sString = Left(sString, (sString.Length) - 148)
       End If
       'sString = sb.ToString()
       reader.Close()

Like I say this works fine when debuging the project locally, but
fails online.

Hopefully someone can help :)
Martin Honnen - 20 Sep 2007 13:14 GMT
> I have a function which reads the xml from a web url into the
> XmlTextReader, and then I work my way through the reader producing
[quoted text clipped - 7 lines]
> properly respond after a period of time, or established connection
> failed because connected host has failed to respond

I don't think it is a problem with your code using XmlTextReader, there
seems to be a network connection problem you will need to investigate.

Signature

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

TheDude5B - 20 Sep 2007 16:07 GMT
> > I have a function which reads the xml from a web url into the
> > XmlTextReader, and then I work my way through the reader producing
[quoted text clipped - 15 lines]
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

I does occur at this stage in the code, because if I put a Try..Catch
statement around it, it catches the error. Can there be something
blocking the XmlTextReader from accessing the XML document at the web
URL?
Martin Honnen - 21 Sep 2007 13:25 GMT
> I does occur at this stage in the code, because if I put a Try..Catch
> statement around it, it catches the error. Can there be something
> blocking the XmlTextReader from accessing the XML document at the web
> URL?

XmlReader under the hood uses WebRequest/HttpWebRequest to establish a
HTTP connection and that error message sounds as if such a connection
cannot be established.
I am not sure how to help, can you post the URL you are trying to access?
Maybe using an XmlUrlResolver helps, see
<URL:http://msdn2.microsoft.com/en-us/library/System.Xml.XmlTextReader.XmlResolver.aspx>
but the error message simply sounds as if it is not possible to
establish a connection at all.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.