XMl 各地区天气情况的详细信息,并将解析的数据入库
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,1、关于DOM文件名:city.php//实现将各地区的天气情况入库
千家信息网最后更新 2025年12月03日XMl 各地区天气情况的详细信息,并将解析的数据入库
1、关于DOM
文件名:city.php
//实现将各地区的天气情况入库
load($url);//读取最外层的节点$city=$dom->getElementsByTagName("city");//print_r($city);die;$len = $city->length;for($i=0;$i<$len;$i++){ $item = $city->item($i); $quName = $item->getAttribute("quName"); //print_r($quName);die; $pyName = $item->getAttribute("pyName"); $cityname = $item->getAttribute("cityname"); $state1 = $item->getAttribute("state1"); $state2 = $item->getAttribute("state2"); $stateDetailed = $item->getAttribute("stateDetailed"); $tem1 = $item->getAttribute("tem1"); $tem2 = $item->getAttribute("tem2"); $windState = $item->getAttribute("windState"); //拼写添加sql语句 $sql = "insert into weather(quName,pyName,cityname,state1,state2,stateDetailed,tem1,tem2,windState)values('".$quName."','".$pyName."','".$cityname."','".$state1."','".$state2."','".$stateDetailed."','".$tem1."','".$tem2."','".$windState."')"; //执行sql语句 set_time_limit(0);//取消脚本执行时间限制 $res = $pdo->exec($sql); //获取省份信息 $dom1=new DOMDocument(); @$dom1->load("http://flash.weather.com.cn/wmaps/xml/".$pyName.".xml"); $citys=$dom1->getElementsByTagName("city"); $leng = $citys->length; for($j=0;$j<$leng;$j++){ $item1 = $citys->item($j); $cityX = $item1->getAttribute("cityX"); $cityY = $item1->getAttribute("cityY"); $cityname = $item1->getAttribute("cityname"); $centername = $item1->getAttribute("centername"); $fontColor = $item1->getAttribute("fontColor"); $pyName = $item1->getAttribute("pyName"); $state1 = $item1->getAttribute("state1"); $state2 = $item1->getAttribute("state2"); $stateDetailed = $item1->getAttribute("stateDetailed"); $tem1 = $item1->getAttribute("tem1"); $tem2 = $item1->getAttribute("tem2"); $temNow = $item1->getAttribute("temNow"); $windState = $item1->getAttribute("windState"); $windDir = $item1->getAttribute("windDir"); $windPower = $item1->getAttribute("windPower"); $humidity = $item1->getAttribute("humidity"); $time = $item1->getAttribute("time"); $url = $item1->getAttribute("url"); //var_dump($humidity);die; $sql1 = "insert into sheng(cityX,cityY,cityname,centername,fontColor,pyName,state1,state2,stateDetailed,tem1,tem2,temNow,windState,windDir,windPower,humidity,time,url)values('".$cityX."','".$cityY."','".$cityname."','".$centername."','".$fontColor."','".$pyName."','".$state1."','".$state2."','".$stateDetailed."','".$tem1."','".$tem2."','".$temNow."','".$windState."','".$windDir."','".$windPower."','".$humidity."','".$time."','".$url."')"; set_time_limit(0);//取消脚本执行时间限制 //$data = $pdo->exec($sql1); //获取市的天气信息 $dom2=new DOMDocument(); @$dom2->load("http://flash.weather.com.cn/wmaps/xml/".$pyName.".xml"); $city1=$dom2->getElementsByTagName("city"); $length = $city1->length; //print_r($length); for($s=0;$s<$length;$s++){ $item2 = $city1->item($s); $cityX = $item2->getAttribute("cityX"); $cityY = $item2->getAttribute("cityY"); $cityname = $item2->getAttribute("cityname"); $centername = $item2->getAttribute("centername"); $fontColor = $item2->getAttribute("fontColor"); $pyName = $item2->getAttribute("pyName"); $state1 = $item2->getAttribute("state1"); $state2 = $item2->getAttribute("state2"); $stateDetailed = $item2->getAttribute("stateDetailed"); $tem1 = $item2->getAttribute("tem1"); $tem2 = $item2->getAttribute("tem2"); $temNow = $item2->getAttribute("temNow"); $windState = $item2->getAttribute("windState"); $windDir = $item2->getAttribute("windDir"); $windPower = $item2->getAttribute("windPower"); $humidity = $item2->getAttribute("humidity"); $time = $item2->getAttribute("time"); $url = $item2->getAttribute("url"); $sql2 = "insert into sheng(cityX,cityY,cityname,centername,fontColor,pyName,state1,state2,stateDetailed,tem1,tem2,temNow,windState,windDir,windPower,humidity,time,url)values('".$cityX."','".$cityY."','".$cityname."','".$centername."','".$fontColor."','".$pyName."','".$state1."','".$state2."','".$stateDetailed."','".$tem1."','".$tem2."','".$temNow."','".$windState."','".$windDir."','".$windPower."','".$humidity."','".$time."','".$url."')"; set_time_limit(0);//取消脚本执行时间限制 $data1 = $pdo->exec($sql2); } }}?>2、XML基于事件,循环出各地区天气信息:jiexi.php
$name,"attrs"=>$attrs); array_push($stack,$tag);} function cdata($parser, $cdata) { global $stack,$i; if(trim($cdata)) { $stack[count($stack)-1]['cdata']=$cdata; } } function endTag($parser, $name) { global $stack; $stack[count($stack)-2]['children'][] = $stack[count($stack)-1]; array_pop($stack);} $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "cdata"); $data = xml_parse($xml_parser,file_get_contents($file)); if(!$data) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } xml_parser_free($xml_parser); print("\n"); print_r($stack); print("\n"); ?>
信息
天气
时间
脚本
限制
语句
情况
事件
外层
文件
文件名
省份
节点
循环
数据
并将
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
win7支持sql数据库
大连市网络安全平台
网络安全公益海报手画
汽车网络技术现在有哪些
实验五 数据库的安全性设计
睿云服务器远程连接不了
网络安全靠人民主题班会记录
迅购网络技术服务中心
和平精英怎么一直连接服务器
谢国庆软件开发
新城区网络安全委员会
有Java 基础学网络安全
软件开发有哪些设计文档
云南化验机构进法院数据库有那些
2022年网络安全法考试题答案
软件开发方式分类
昆仑服务器上传镜像
c服务器端开发
5年级学生如何学习软件开发
数据库标准语言怎么创建
徐州企业网络安全
网络安全公益海报手画
员工信息数据库
新城区网络安全委员会
软件开发有哪些设计文档
sql数据库安装报未知
个人怎么建立计算机服务器
临沂国企招软件开发大学生
珠海专业软件开发大概多少钱
vs如何使用数据库