'', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.

I'm getting the following error when loading an xml doc which is an rss feed:
'', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.

I presume they have included a space at the front of the xml have they?

Obviously I can't change that as am just using the feed, this is how I load it:
Dim xmlDoc As New XmlDocument
xmlDoc.Load("http://www.bournemouthecho.co.uk/news/rss/")

Is there anything I can do to that to work around the problem?
scm0smlAsked:
Who is Participating?
 
Gary DavisDir Internet SvcsCommented:
Well, it depends on what you are doing with the received response. Here is my test case based on yours:
   
Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create("http://www.bournemouthecho.co.uk/news/rss/"), HttpWebRequest)
webReq.AutomaticDecompression = DecompressionMethods.GZip

Dim resp As HttpWebResponse = DirectCast(webReq.GetResponse(), HttpWebResponse)
Dim xml As String
Using sr As New StreamReader(resp.GetResponseStream())
  xml = sr.ReadToEnd()
End Using

Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(xml)

Response.Write("XML starts: " & Server.HtmlEncode(xmlDoc.InnerXml.Substring(0, 100)))

Open in new window

0
 
Paolo SantiangeliConsulente InformaticoCommented:
Hi,
did you try a replace workaround?

have a look here
http://forums.asp.net/t/1120421.aspx
0
 
scm0smlAuthor Commented:
Right I needed it in vb.net so used a convertor and got:

        Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create("http://www.bournemouthecho.co.uk/news/rss/"), HttpWebRequest)
        Dim response As HttpWebResponse = DirectCast(webReq.GetResponse(), HttpWebResponse)
        Dim xml As String = String.Empty
        Using sr As New StreamReader(response.GetResponseStream())
            xml = sr.ReadToEnd()
        End Using

        xml = xml.Replace(Convert.ToString(CByte(&H1F)), String.Empty)

should this line:
        xml = xml.Replace(Convert.ToString(CByte(&H1F)), String.Empty)

be using &H1F??

When I try:
xml = xml.Replace(Convert.ToString(CByte("0x1F")), String.Empty)

I get:
xml = xml.Replace(Convert.ToString(CByte("0x1F")), String.Empty)

Any ideas?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
grayeCommented:
OK, you lost me (or I'm completely blind)....

What's the difference between these two?
xml = xml.Replace(Convert.ToString(CByte("0x1F")), String.Empty)
xml = xml.Replace(Convert.ToString(CByte("0x1F")), String.Empty)

0
 
scm0smlAuthor Commented:
Sorry, I meant to say I get:
Conversion from string "0x1F" to type 'Byte' is not valid.


I'm an idiot!
0
 
grayeCommented:
OK... I'm following now.  In VB, the byte literal is done with &H.  So in your example, it would be:

xml = xml.Replace(Convert.ToString(CByte(&H1F)), String.Empty)
0
 
scm0smlAuthor Commented:
I'm now getting:
Illegal characters in path.

Something weird going on, when I debug the xml it is:¿
????
0
 
grayeCommented:
Can you post a small chunk of the XML file you're dealing with?

0
 
scm0smlAuthor Commented:
I tried to debug the xml to see what I was getting, it came out with what was in my last post?!

Seems the replace has messed this up?

The feed I'm getting the original xml from is:
http://www.bournemouthecho.co.uk/news/rss/

0
 
grayeCommented:
I already tried that.. after it gets rendered by my browser, and I do a "view source", it looks clean as a whistle.

<?xml version="1.0"?>
<?xml-stylesheet......

That's why I suggested that you capture the incomming RSS feed via code, save it to disk, and the post the results here for us to see.
0
 
scm0smlAuthor Commented:
apologies for not finishing this post off, the issue is still there for me.

can you put this simple code into a test page?

Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create("http://www.bournemouthecho.co.uk/news/rss/"), HttpWebRequest)
            Dim response As HttpWebResponse = DirectCast(webReq.GetResponse(), HttpWebResponse)
            Dim xml As String = String.Empty
            Using sr As New StreamReader(response.GetResponseStream())
                xml = sr.ReadToEnd()
            End Using

Straight away there is something wrong with the string xml....

Any ideas?
0
 
scm0smlAuthor Commented:
That example is c#.

I have converted to vb.net but still not working.

Below is a simple piece of code that could go on a test page for someone to easily replicate the problem....
Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create("http://www.bournemouthecho.co.uk/news/rss/"), HttpWebRequest)
            Dim response As HttpWebResponse = DirectCast(webReq.GetResponse(), HttpWebResponse)
            Dim xml As String = String.Empty
            Using sr As New StreamReader(response.GetResponseStream())
                xml = sr.ReadToEnd()
            End Using

Open in new window

0
 
scm0smlAuthor Commented:
or simply:
Dim xmlDoc As New XmlDocument
            xmlDoc.Load("http://www.bournemouthecho.co.uk/news/rss/")
0
 
Gary DavisDir Internet SvcsCommented:
The input is coming in compressed. To uncompress, add this line before getting the response:

        webReq.AutomaticDecompression = DecompressionMethods.GZip

This is using your test case. Displaying the xml variable was what clued me in to the issue.

See: http://stackoverflow.com/questions/2973208/automatically-decompress-gzip-response-via-webclient-downloaddata

Gary Davis
0
 
scm0smlAuthor Commented:
im getting:
Illegal characters in path now?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.