我在嘗試加載到XDocument時抱怨隨機錯誤,抱怨我的XML中的無效字符。隨機XML例外 - '',十六進制值0x1F,是無效字符
' ', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
這發生在這21個位置中的一個位置上,但有時不會發生。這是BBC的RSS,因此它是嚴格管理和編碼的XML。當我打開,我已經下載並有一個問題的文件,他們有時看起來像這裏面:
I-ÛnÛ8†ïôhQ[¤¤ÈvÙÁÆEZ「¢hÒä2 %Ú""‰IÅÍ[õúd;」åSì´nÐ,öƦ43üçð‘P|òÈáž+-d9t<—:ÀËD¦¢œ ¯WgÝs2zý*VZº–:bFC'3¦Š™Ïçî<p¥šŸÒüF§uœq‰Q[®‹Wûb鬵}ÔF%€8ÉXYò¼yÀG+墼ƒLñéj?YñÒÍÅ=w'「ÄM¤[ß‘9g&ãŠL9O5á%ñ{Gƒ°L‚」=L¥â ÓÆmtχŽæùÔóPñ¡Ãª* 3˜AwX„d™„&ç£ÓÓ1Ü,4 g톀;|È™žÉy¾–ÂðþÁ¦²ˆÉ"´ÝÇÖ1ÚèÈnîmÊ1i\Û°」ëD‰Ê&7 ºXL7Å[m˜*YÀF’e’×vš0_¾2¼¨¸b¦VX™Â\à(qŸ¢©>&›j˼Y9«ÙŒ8ÚW1‘Õƒ³ÌŒÆËUoÆoáT #t†ÿ’¥6[›ÈXªJªFªšsØÛÃU¡ KSaY~kÁÑ™A\mÅ–)7Lä:&ëÚŒªzòž>ºÊêÐc¸ÀŽùÔÀëGÞ ÂÅ;êQ「¥c'ŠuYnê¸SòåصÁÚ[ªx4zê®OÒd¡‰Hd‰¿e*îEZcÂþíâ/oey›ÛŠo'3âùîLLcbEVŠÏ# ç"5Ù¨ëÅd±Z2Þ´ØZÚeÛ5²Ù¶ûP<n!ÎAiÄ6‚s_˜Àá_ˆRuWk"#èÿø>†7GáïgowÚxpQ'(6¤KÛû—⸱'ã½ÀyÛˆ>Ie2DA#œùCk¿¬ð²ÁÈ¢Ê:p-´˜ˆ\¬ôš«ø eÚÏŠkÝ÷ŠI>Ö…H¯>ýṆ/BßE࣯Ìóz¡wnÁº¬KÍñ<ù^äypzyµï|>yŒœÕ/ ýO;Ç~ )Ë5wjt—vJ—†]z|åõ"J#¿çŽ(ÊEVÏn¿!ÖÜûQ%EiFaèz¡B÷ÈõÃ~/ˆÉ–}Åש½x)ÑÀu「¡Æ¹¬±éìÛ ™pØLøÅô~ à/ó;à„ìBjñ„KY?Iªç†*Ââm³Úëm²ìeU ±4Œpªë6¿Áÿ_o‹ßVË¥ô¿ä÷ÒNv÷zÜ] BŸ8\ðáý€ýßx3¿' ÞLp?À{¨ ¦ÖtÃ~‡Ú
-ÚðYÔE¼μþμÖKQ
這是否損壞?當我更新這些天氣位置時,我有問題嗎?這裏是我的代碼...
Module_XML_Download:
Public Sub DownloadXML(ByVal URL As String, ByVal SaveAs As String)
Try
Dim WebClient As New System.Net.WebClient()
WebClient.DownloadFile(URL, SaveAs)
If My.Settings.LogXMLDownloaded = True Then
Module_Log.WriteLog(Now.ToString & " XML Downloaded: " & SaveAs)
End If
Catch _Exception As Exception
' Error
' MsgBox("Exception caught in process: {0}", _Exception.ToString())
If My.Settings.LogXMLDownloadError = True Then
Module_Log.WriteLog(Now.ToString & " XML DL Error: " & _Exception.Message)
End If
End Try
End Sub
和:
Public Sub DownloadWeather()
If IsConnectionAvailable() = True Then
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2657832/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Aberdeen.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2656752/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Aviemore.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2653609/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Barra.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2650752/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Dundee.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2650798/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Dumfries.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2651245/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Dingwall.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2650225/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Edinburgh.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2648579/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Glasgow.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2636239/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Harris.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2646088/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Inverness.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2655051/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Islay.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2636790/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Lewis.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2635754/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Mull.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2641108/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Oban.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2645198/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Orkney.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2640358/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Perth.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2644605/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Shetland.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2640006/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Skye.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2635881/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Thurso.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2643811/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Uist.xml")
Module_XML_Download.DownloadXML("http://open.live.bbc.co.uk/weather/feeds/en/2635199/3dayforecast.rss", My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Ullapool.xml")
End If
End Sub
然後我裝替補的一個示例:
Public Sub WeatherAviemore_Load()
'weatherDoc = XDocument.Load("http://open.live.bbc.co.uk/weather/feeds/en/2656752/3dayforecast.rss")
weatherDoc = XDocument.Load(My.Settings.DataMainFolder & "\" & My.Settings.DataWeatherXMLFolder & "\Aviemore.xml")
PopulateWeatherListBox(weatherDoc, MainForm.WeatherAviemoreListBox, "Aviemore", "An Aghaidh Mhòr")
End Sub
RSS文檔看起來像這樣: – rwmck 2013-05-10 08:39:01
<?xml version =「1.0」encoding =「UTF-8」?> etc ... –
rwmck
2013-05-10 08:39:30
因此,當異常沒有發生時,文件看起來像你在這裏寫的(<?xml等等......),當問題發生時,文件就像是有問題了(Í-ÛnÛ8†ï等等)? – IvanH 2013-05-10 08:48:54