Parsing XML data with php

I am trying to pull text from a single element in an xml file, i was able to pull the entire file but i really only need a couple of lines from the file...

On this page i was able to pull the entire xml file ( )

But when i try to just single out one line from that file.

This is the error i am receiving:

Fatal error: Call to a member function getbyElementID() on a non-object in /home/content/74/8620474/html/current_data.php on line 9

If anyone could help me that would be amazing, i have been struggling with this for hours.

This is my code:


function startElemHandler($parser, $name, $attribs) 
    if (strcasecmp($name, "current_observation") ==0 ) {
        echo "<div id='waves'>\n";
    if (strcasecmp($name, "wave_height_ft") ==0) {

            echo $waveHeight->asXML();


function endElemHandler($parser, $name)
    if (strcasecmp($name, "current_observation") ==0 ) {
        echo "</div>";


$parser = xml_parser_create();
xml_set_element_handler($parser, startElemHandler, endElemHandler);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

$strXML = implode("",file(""));

xml_parse($parser, $strXML);




You have a few fundamental flaws with your code but you are essentially asking how to parse an XML file. I suggest using PHP's DOMDocument with DOMXPath to extract the data you need. Here is some example code:

$xml = file_get_contents('weather.xml');
$dom = new DOMDocument();
$domx = new DOMXPath($dom);
$entries = $domx->evaluate("//wave_height_ft");
$arr = array();
foreach ($entries as $entry) {
    $arr[] = '<' . $entry->tagName . '>' . $entry->nodeValue .  '</' . $entry->tagName . '>';

Need Your Help

Mono and ASP.NET Authentication authentication mono

Does anyone know how to get to work the authentication mechanism configured using Web Site Administration Tool under Linux running Mono? Is it even possible?

Trying to perform a a linq query that joins two tables, has a where clause, and groups the results

sql-server linq linq-to-sql

I am sure it is a simple, but I can't quite get it to work. This is the SQL query I am using as my reference. I want to make this same thing happen with LINQ.