2

I have xml. It's movie showtimes, and i try parse.

<shows>
    <show id="160575" film_id="7043" cinema_id="89" hall_id="241">
        <begin>2012-11-15</begin>
        <end>2012-11-18</end>
        <times>
            <time time="10:30:00">
                <prices>20, 30</prices>
                <note><![CDATA[]]></note>
            </time>
        </times>
    </show>
</shows>

I parse my XML and echo content : String "film_id_m" must be 7043 from the tag .

$xmlstr = file_get_contents('test.xml');
$x = new SimpleXMLElement($xmlstr); 
$id_f = 89;
$cinema_id = "//show[@cinema_id=".$id_f."]";

$cinema=$x->xpath($cinema_id);

///////////string///////////////////
$begin_m = $cinema[0]->begin;
$end_m = $cinema[0]->end;
$film_id_m = ????????; 



/////////echo//////////////////////
echo "<b>BEGIN: </b>".$begin_m."<br>"; 
echo "<b>END: </b>".$end_m."<br>"; 
echo "<b>FILM ID: </b>".$film_id_m."<br>"; 

P.S: Sorry for my english.

2
  • $cinema[0]->attributes("film_id") Commented Nov 20, 2012 at 12:26
  • SimpleXmlElement attributes :) Commented Nov 20, 2012 at 12:27

1 Answer 1

2

As film_id is an attribute of the currently processed element, you can retrieve its value with either...

$film_id_m = $cinema[0]->attributes()->film_id;

... or just...

$film_id_m = $cinema[0]['film_id'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.