Hey everyone,

I'm attempting to parse through the google calendar feed. The problem comes with parsing the "where" tag. When an address is in the "where" it comes back blank; however, when it is just a word, it works fine.

It seems that with an address google adds a <georss:where> tag on top of the normal <gd:where> tag making the php check the wrong tag.

I have been experimenting with getElementsByTagNameNS() but I keep getting errors. What's the proper way to grab the "gd:where" and not the "georss:where".

The PHP:

$entries = $doc->getElementsByTagName( "entry" );
foreach ( $entries as $entry ) {
...
$places = $entry->getElementsByTagName("where");          
$where = $places->item(1)->getAttributeNode("valueString")->value;

The XML:

<georss:where>
      <gml:Point>
        <gml:pos>46.46261 -109.39144</gml:pos>
      </gml:Point>
    </georss:where>
    <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>
    <gd:transparency value='http://schemas.google.com/g/2005#event.transparent'/>
    <gCal:uid value='vl3ueretsi1dissg98q3fplmto@google.com'/>
    <gCal:sequence value='2'/>
    <gd:when startTime='2009-09-08T10:00:00.000-04:00' endTime='2009-09-08T11:00:00.000-04:00'/>
    <gd:who rel='http://schemas.google.com/g/2005#event.organizer' valueString='UF Theatre Department Dates of Interest' email='oqtn87idrk91p07pco6a5rjgpo@group.calendar.google.com'/>
    <gd:where valueString='1004 1st Dr. Orlando, FL 32809'/>

    You only need the ...NS() functions if you actually care about namespace restrictions, else you get ALL the where tags, no matter what their namespace is.

    $str = <<<EOT
    <tutti xmlns:georss="http://www.altavista.com" xmlns:gml="http://www.yahoo.com"
    xmlns:gd="http://www.google.com" xmlns:gCal="http://www.baidu.com">
    	<georss:where>
    		<gml:Point>
    			<gml:pos>46.46261 -109.39144</gml:pos>
    		</gml:Point>
    	</georss:where>
    	<gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>
    	<gd:transparency value='http://schemas.google.com/g/2005#event.transparent'/>
    	<gCal:uid value='vl3ueretsi1dissg98q3fplmto@google.com'/>
    	<gCal:sequence value='2'/>
    	<gd:when startTime='2009-09-08T10:00:00.000-04:00' endTime='2009-09-08T11:00:00.000-04:00'/>
    	<gd:who rel='http://schemas.google.com/g/2005#event.organizer' valueString='UF Theatre Department Dates of Interest' email='oqtn87idrk91p07pco6a5rjgpo@group.calendar.google.com'/>
    	<gd:where valueString='1004 1st Dr. Orlando, FL 32809'/>
    </tutti>
    EOT;
    
    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->loadXML($str);
    $list = $dom->getElementsByTagName('where');
    echo '<br/>This gets all where nodes (without NS):<br/>';
    foreach($list as $n) {
    	if ($att = $n->getAttribute('valueString'))
    		echo $att . '<br/><br/>';
    	else
    		echo $n->nodeValue . '<br/><br/>';
    
    }
    
    $gdw = $dom->getElementsByTagNameNS("http://www.google.com", "where");
    echo '<br/>This only gets gd:where (using NS):<br/>';
    foreach($gdw as $n) {
    	if ($att = $n->getAttribute('valueString'))
    		echo $att . '<br/><br/>';
    	else
    		echo $n->nodeValue . '<br/><br/>';
    }

      Thanks a lot!

      I was trying to use

      getElementsByTagNameNS("gd","where"); 

      but I really needed

      getElementsByTagNameNS("http://schemas.google.com/g/2005","where"); 

      I did not think to figure out what "gd" is defined as.

      Here's the top of my google feed (if anyone was curious):

      <feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gml='http://www.opengis.net/gml' xmlns:georss='http://www.georss.org/georss' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gCal='http://schemas.google.com/gCal/2005' xmlns:gd='http://schemas.google.com/g/2005'>
        Write a Reply...