stephenreid27 Posted May 8, 2007 Share Posted May 8, 2007 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 More sharing options...
stephenreid27 Posted May 8, 2007 Author Share Posted May 8, 2007 Any ideas anyone? Is it possible? Need more info? Thanks :-) Link to comment https://forums.phpfreaks.com/topic/50498-parsing-xml-georss/#findComment-248556 Share on other sites More sharing options...
Barand Posted May 8, 2007 Share Posted May 8, 2007 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 More sharing options...
pokeycam Posted May 10, 2007 Share Posted May 10, 2007 Hey thanks heaps! That works like a dream. Thanks Stephen Link to comment https://forums.phpfreaks.com/topic/50498-parsing-xml-georss/#findComment-249527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.