LoadXML in XMLDocument

  • Thread starter César A. Fong Espinola
  • Start date
C

César A. Fong Espinola

Hi, a few weeks ago i have prepared a demo that consuming an rss. Our RSS
(www.todopocketpc.com/rss/rss.asp) would be our consumed rss. But when i try
to execute this code in .Net CF

Public Function obtenerRSS(ByVal pistrURL As String) As XmlDocument
Try
Dim xmldoc As New XmlDocument
Dim writer As XmlTextWriter = New XmlTextWriter(App_Path() & "rss.xml",
Nothing)
Dim request As HttpWebRequest = CType(WebRequest.Create(pistrURL),
HttpWebRequest)
request.ContentType = "text/xml"
Dim response As HttpWebResponse = CType(request.GetResponse,
HttpWebResponse)
xmldoc.Load(response.GetResponseStream())
writer.Formatting = Formatting.Indented
xmldoc.Save(writer)
response.Close()
writer.Close()
Return xmldoc
Catch e As System.Exception
MsgBox(e.ToString)
End Try
End Function
Returns me an error i notice this because our site has this encoding for
being a spanish web site is <?xml version="1.0" encoding="ISO-8859-1" ?>
For my test i have to create another page without the tag encoding and of
course i have to parse and omitted the accented characters and some signs.
is this a bug for .Net CF or do i have to use another method???

Thanks in advanced
Cesar
 
A

Alex Feinman [MVP]

Does your web page return correct encoding in the HTTP headers? I.e. does it
match the one in the xml document?
 
A

Alex Feinman [MVP]

There is no iso-8859-1 codepage on CF/PPC. If you replace it with UTF-8 you
should be able to use western european characters seamlessly
 
C

César A. Fong Espinola

Thanks Alex for your answer i try using all valid encoding for net cf -ppc
but anyone goes fine..i.e. UTF-8 doesn't support accented lowels... i.e. í
á é ú ó so it seems a limititation por net cf.. because it restricts all
spanish xml sites...

So i have to create my own rss reader without using xmldocument ..... :s

Any comments or do you know if this will be added in next CF service pack?

Thanks in advanced

César
 
A

Alex Feinman [MVP]

I might have a solution for you...
If you replace the code in ObtenerRss with :

Dim response As HttpWebResponse = CType(request.GetResponse,
HttpWebResponse)

Dim rdr As StreamReader = New StreamReader(response.GetResponseStream(),
Encoding.GetEncoding(1252))

xmldoc.Load(New XmlTextReader(rdr))

it will load xml without an issue. The question is, how to find the
appropriate codepage. Your server (http://www.todopocketpc.com/rss/rss.asp)
does not return a valid charset in the response headers. This means, you
will need to read response into a byte buffer and use XmlReader to parse a
first PI out of it to get the encoding. Of course instead of parsing you can
just try several differnt codepages
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top