php 解析xml格式数据,用php解析XML数据

我试图从一个XML文件中的单个元素拉文本,我能够拉整个文件,但我真的只需要从文件中的几行...

在这个页面上,我能够将整个xml文件(http://smyrnainlet.com/testing.php)

但是当我尝试从该文件中挑出一行时。

http://smyrnainlet.com/current_data.php

这是我收到的错误:

致命错误:在第9行的/home/content/74/8620474/html/current_data.php中的非对象上调用成员函数getbyElementID()

如果任何人都可以帮助我,那将是惊人的,我一直在为此奋斗几个小时。

这是我的代码:

function startElemHandler($parser, $name, $attribs)

{

if (strcasecmp($name, "current_observation") ==0 ) {

echo "

\n";

}

if (strcasecmp($name, "wave_height_ft") ==0) {

$waveHeight->getbyElementID("wave_height_ft");

echo $waveHeight->asXML();

}

}

function endElemHandler($parser, $name)

{

if (strcasecmp($name, "current_observation") ==0 ) {

echo "

";

}

}

$parser = xml_parser_create();

xml_set_element_handler($parser, startElemHandler, endElemHandler);

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

$strXML = implode("",file("http://www.weather.gov/xml/current_obs/41009.xml"));

xml_parse($parser, $strXML);

xml_parser_free($parser);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值