以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  【已解决】[求助]这个怎么解析?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=133089)

--  作者:zto001
--  发布时间:2019/4/6 12:09:00
--  【已解决】[求助]这个怎么解析?
求助:

这个怎么解析?
<?xml version="1.0" encoding="utf-8"?>
<AlermInfo dt="20190406115308" hourType="24"><RoadIcing/><SnowStorm/><RainStorm><Station stati areaId="1011310" stati lon="81.303" lat="43.910" signalType="暴雨" signalLevel="蓝色" issueTime="20190405184000" relieveTime="20190407050000" issueC/>

..........


Dim hc As New HttpClient("http://www.weather.com.cn/data/alarm_xml/alarminfo.xml")
Dim xo As XObject = XObject.Parse(hc.GetData)
msgbox(xo("stationName"))
这样写获取不出来
stati 
怎么写才能获取?


[此贴子已经被作者于2019/4/7 10:08:42编辑过]

--  作者:有点蓝
--  发布时间:2019/4/6 13:55:00
--  
无法使用XObject。

论坛搜“xml

--  作者:zto001
--  发布时间:2019/4/6 17:00:00
--  
Dim hc As New HttpClient("http://www.weather.com.cn/data/alarm_xml/alarminfo.xml")
Dim txt As String = hc.GetData
Dim xmlDoc As New System.XML.XmlDocument
xmlDoc.Loadxml(txt)
Dim ndList  = xmlDoc.GetElementsByTagName("AlermInfo")
    output.show("1")   ’没问题
For Each nd As object In ndlist
    output.show("2")   ’没问题
    output.show(nd("PANELQUANTITY").Innertext)   ’到这里就不会写了。我那里面没有元素块,AlermInfo可能是唯一的一块了
Next

--  作者:zto001
--  发布时间:2019/4/6 17:04:00
--  
<?xml version="1.0" encoding="utf-8"?>
<AlermInfo dt="20190406115308" hourType="24"><RoadIcing/><SnowStorm/><RainStorm><Station stati areaId="1011310" statibackground-color: rgb(255, 0, 0);">伊犁哈萨克自治州" lon="81.303" lat="43.910" signalType="暴雨" signalLevel="蓝色" issueTime="20190405184000" relieveTime="20190407050000" issueCbackground-color: rgb(255, 0, 0);">伊犁州气象台2019年4月5日18时40分发布暴雨蓝色预警信号:预计今日夜间至明日夜间,霍城县与伊宁县的北部山区、尼勒克县东部地区、新源县大部地区及巩留县南部山区将出现24小时内达24.1毫米以上的暴雨。暴雨可能引发局地洪水和泥石流、滑坡等地质灾害,注意防范。(预警信息来源:国家预警信息发布中心)"/>
<Station stati areaId="10113" stati lon="" lat="" signalType="暴雨" signalLevel="蓝色" issueTime="20190405180000" relieveTime="20190406180000" issueC/></RainStorm><Hail/><Gale>

红色背景区怎么获取?

--  作者:有点蓝
--  发布时间:2019/4/6 17:37:00
--  
Dim ndList  = xmlDoc.GetElementsByTagName("AlermInfo")
For Each  nd As object In ndlist
    output.show( nd.Attributes("dt").value)
Next

--  作者:zto001
--  发布时间:2019/4/7 10:08:00
--  
Dim hc As New HttpClient("http://www.weather.com.cn/data/alarm_xml/alarminfo.xml")
Dim txt As String = hc.GetData
Dim xmlDoc As New System.XML.XmlDocument
xmlDoc.Loadxml(txt)
Dim ndList  = xmlDoc.GetElementsByTagName("Station")
For Each  nd As object In ndlist
    output.show( nd.Attributes("stationName").value)  \'stationName
    output.show( nd.Attributes("signalType").value)   \'signalType
    output.show( nd.Attributes("signalLevel").value)  \'signalLevel
    output.show( nd.Attributes("issueTime").value)  \'issueTime
    output.show( nd.Attributes("relieveTime").value)  \'relieveTime
    output.show( nd.Attributes("issueContent").value)  \'issueContent
Next