'', 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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.