Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

'', 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?
Avatar of Paolo Santiangeli
Paolo Santiangeli
Flag of Italy image

Hi,
did you try a replace workaround?

have a look here
http://forums.asp.net/t/1120421.aspx
Avatar of scm0sml
scm0sml

ASKER

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?
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)

Avatar of scm0sml

ASKER

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


I'm an idiot!
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)
Avatar of scm0sml

ASKER

I'm now getting:
Illegal characters in path.

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

Avatar of scm0sml

ASKER

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/

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.
Avatar of scm0sml

ASKER

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?
Avatar of scm0sml

ASKER

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

Avatar of scm0sml

ASKER

or simply:
Dim xmlDoc As New XmlDocument
            xmlDoc.Load("http://www.bournemouthecho.co.uk/news/rss/")
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
Avatar of scm0sml

ASKER

im getting:
Illegal characters in path now?
ASKER CERTIFIED SOLUTION
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial