SimpleXML problem

Discussion in 'PHP' started by avraam, May 20, 2010.

  1. #1
    Hi everybody, I am new in the forum... I have this problem:

    Parse error: syntax error, unexpected ':'

    Phpcode

    <?php

    $search_artist=$_POST["textfield4"];
    $url='http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist='.$search_artist.' &api_key=b25b959554ed76058ac220b7b2e0a026';
    $lfm = simplexml_load_file($url);
    $name=$lfm->events->event[0]->venue->name;
    $lat=$lfm->events->event[0]->venue->location->geo: point->geo:lat;
    ?>

    XMLfile
    <geo: point>
    <geo:lat>36.116143</geo:lat>
    <geo:long>-115.176416</geo:long>
    </geo: point>


    How can I get geo:lat value ;
     
    avraam, May 20, 2010 IP
  2. jaholden

    jaholden Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You appear to have a space after the colon. I don't think a colon is valid in a member variable name either.

    Try just referencing ->point->lat instead, as the geo: part is a namespace.

    Or use DomDocument and DomXPath instead of simplexml.
     
    jaholden, May 20, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3

    This isnt valid XML.

    You will need to correct the XML in order to process it correctly. You are also not referencing the name spaces correctly. You might want to refer
    to something like the following in order to understand namespaces and attributes correctly;

    http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/

    OR..... if it is just the LAT you are after you can do something like;

    preg_match("|<geo:lat>(.+?)</geo:lat>|i", $your_xml_feed, $match);
    print $match[1];
    PHP:
    OUTPUT: 36.116143
     
    lukeg32, May 20, 2010 IP
  4. avraam

    avraam Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    the space before colone is because : P=:p (emoticon appears)... for that reason I leave a space so you can understand the code.

    The XML file is this location ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=madonna&api_key=b25b959554ed76058ac220b7b2e0a026
     
    avraam, May 20, 2010 IP