Jump to content

Recommended Posts

Hello,

 

I'm wishing to import that variables of an XML (geoRSS) into my php application.  I will list the code and explain what I've done

 

test.xml -  the standard XML document is geoRSS schema

<?xml version="1.0"?>
        <rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:ymaps="http://api.maps.yahoo.com/Maps/V2/AnnotatedMaps.xsd">
                <channel>
                        <title>Vessels</title>
                        <description>by Fleetviewonline.com</description>
                        <link>http://www.fleetviewonline.com</link>

                        <ymaps:Groups>
                        <group>
                                <Title>Vessels</Title>
                                <Id>VesselsGroup</Id>
                                <BaseIcon width="44" height="39">
                                <![CDATA[http://www.fleetviewonline.com/services/rss/ship.gif]]></BaseIcon>
                        </group>

                        </ymaps:Groups>

                        <item>
                                <title>Boat1</title>
                                <link>http://www.fleetviewonline.com</link>
                                <ymaps:GroupId>VesselsGroup</ymaps:GroupId>
                                <description><![CDATA[ Date: 2007-05-08 11:58:00Z Position: 49° 29' 12" 00 S 167° 27' 16" 80 W Course: 308° Speed: 009.1  kn.]]></description>
                                <geo:lat>-49.4866666666667</geo:lat>
                                <geo:long>-167.454666666667</geo:long>
                        </item>

                        <item>
                                <title>Boat2</title>
                                <link>http://www.fleetviewonline.com</link>
                                <ymaps:GroupId>VesselsGroup</ymaps:GroupId>
                                <description><![CDATA[ Date: 2007-05-08 11:58:00Z Position: 49° 29' 12" 00 S 167° 27' 16" 80 W Course: 308° Speed: 009.1  kn.]]></description>
                                <geo:lat>-49.4866666666667</geo:lat>
                                <geo:long>-167.454666666667</geo:long>
                        </item>
                </channel>
        </rss>

 

Here is the parsing bit of code which gets in the above XML document.  I just want it to display the value inside the <geo:lat> tag of boat1.

 

function xmlParser(){
        @$xml = simplexml_load_file('test.xml');
        $currentLat = $xml->channel[0]->item->geo->lat;
        echo $currentLat;
}

 

I believe the issue is on line 3 ( $currentLat = $xml->channel[0]->item->geo->lat).  I can get the title 'Boat1' if I change that line to  $currentLat = $xml->channel[0]->item->title;

 

I would love any help on this.

 

Regards,

 

Stephen

Link to comment
https://forums.phpfreaks.com/topic/50498-parsing-xml-georss/
Share on other sites

there's this

<?php
$xtxt=<<<XML
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:ymaps="http://api.maps.yahoo.com/Maps/V2/AnnotatedMaps.xsd">
                <channel>
                        <title>Vessels</title>
                        <description>by Fleetviewonline.com</description>
                        <link>http://www.fleetviewonline.com</link>

                        <ymaps:Groups>
                        <group>
                                <Title>Vessels</Title>
                                <Id>VesselsGroup</Id>
                                <BaseIcon width="44" height="39">
                                <![CDATA[http://www.fleetviewonline.com/services/rss/ship.gif]]></BaseIcon>
                        </group>

                        </ymaps:Groups>

                        <item>
                                <title>Boat1</title>
                                <link>http://www.fleetviewonline.com</link>
                                <ymaps:GroupId>VesselsGroup</ymaps:GroupId>
                                <description><![CDATA[ Date: 2007-05-08 11:58:00Z Position: 49° 29' 12" 00 S 167° 27' 16" 80 W Course: 308° Speed: 009.1  kn.]]></description>
                                <geo:lat>-49.4866666666667</geo:lat>
                                <geo:long>-167.454666666667</geo:long>
                        </item>

                        <item>
                                <title>Boat2</title>
                                <link>http://www.fleetviewonline.com</link>
                                <ymaps:GroupId>VesselsGroup</ymaps:GroupId>
                                <description><![CDATA[ Date: 2007-05-08 11:58:00Z Position: 49° 29' 12" 00 S 167° 27' 16" 80 W Course: 308° Speed: 009.1  kn.]]></description>
                                <geo:lat>-49.4866666666667</geo:lat>
                                <geo:long>-167.454666666667</geo:long>
                        </item>
                </channel>
        </rss>
XML;

    $xml = simplexml_load_string($xtxt);
    $ar = $xml->xpath("/rss/channel/item/title");
    $key = array_search('Boat1', $ar);
    
    $ar = $xml->xpath("/rss/channel/item/geo:lat"); 
    echo $ar[$key];
?>

Link to comment
https://forums.phpfreaks.com/topic/50498-parsing-xml-georss/#findComment-248622
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.