从Web加载XML文档 [英] Load a XML document from a web

查看:61
本文介绍了从Web加载XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网站加载一个xml文档到我的程序

所以我写了这些行:



  Dim  xDoc 作为 XmlDocument =  XmlDocument()xDoc.Load(  http://www.ims.gov.il/ims/PublicXML/ isr_cities.xml





有时它运作良好,但有时会失败

它失败有时会抛出这个异常:

尝试了太多的自动重定向。

有时看起来好像一切都好但是无法将xml文档加载到我的对象是XmlDocument

i发现它因为在属性innerxml

而不是包含我的文档的xml它包含html如:



< pre lang =HTML>< html>< body>< script> document.cookie ='bbbbbbb = 53cf4d 9cbbbbbbb_53cf4d9c; path = /'; window.location.href = window.location.href;< / script>< / body>< / html>







我该怎么办才能修好它?



请帮帮我 - <你非常紧急 !!!!

非常感谢



我是什么尝试过:



 xDoc =  XmlDocument( )
xDoc.Load( http://www.ims.gov.il/ims/PublicXML/ isr_cities.xml
rssNodes = xDoc.SelectNodes( / IsraelCitiesWeatherForecastMorning / Location





但它失败

解决方案

问题是不是编码,这是网站的问题。与网站管理员交谈。抱歉,但这对任何人来说都不紧急。


这两个症状都提示连接(响应缓慢)问题...

作为理查德告诉你,代码没有任何问题,所以你必须以其他方式解决偶然的失败...

将你的负载包装在try catch块中并重复它直到XML加载完美(可能是模式检查)...

将XML缓存在您自己的服务器上也是一个好主意,并且每天只加载一次或两次(在任何情况下,气象数据都不会变化太快)...

I want to load a xml document from a web to my program
so i wrote these lines:

Dim xDoc As XmlDocument = New XmlDocument()            xDoc.Load("http://www.ims.gov.il/ims/PublicXML/isr_cities.xml")



sometimes it works well,but sometimes it fail
when it fail sometimes it throw this exception :
"Too many automatic redirections were attempted."
and sometimes it look like everything okay but it is fail to load the xml document to my object of "XmlDocument"
i discovered it because in the property "innerxml"
instead of containing xml of my document it containing html like:

<pre lang="HTML"><html><body><script>document.cookie='bbbbbbb=53cf4d9cbbbbbbb_53cf4d9c; path=/';window.location.href=window.location.href;</script></body></html>



what can I do in order to fix it ???

please help me -it very urgent!!!!
thank you so much

What I have tried:

xDoc = New XmlDocument()
                xDoc.Load("http://www.ims.gov.il/ims/PublicXML/isr_cities.xml")
                rssNodes = xDoc.SelectNodes("/IsraelCitiesWeatherForecastMorning/Location")



but it fail

解决方案

The problem is not one of coding, it is an issue with the website. Talk to the web master about it. And sorry, but it is not at all urgent to anyone here.


Both symptoms are hint to a connection (slow response) problem...
As Richard told you, there is nothing wrong with the code, so you have to solve the occasional failures in an other way...
Wrap your load in a try catch block and repeat it until the XML loaded perfectly (probably a schema check)...
Also a good idea to cache the XML on your own server, and only load it once or twice a day (in any case meteorological data does not change too fast)...


这篇关于从Web加载XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆