0

This question is about querying an XML file. The file structure is below:
Inline Code Example Here

<?xml version="1.0" encoding="UTF-8"?>
<descriptions>
    <image>
        <name>run.jpg</name>
        <text>Running around the lake</text>
    </image>
    <image>
        <name>sail.jpg</name>
        <text>Sailing around the lake</text>
    </image>
    <image>
        <name>track.jpg</name>
        <text>Tracking up the mountain</text>
    </image>
...
    <image>
        <name>Steven.jpg</name>
        <text>Steven Bullon is a photographer</text>
    </image>
</descriptions> 

If know the name of the picture how do I get back the text that goes with the picture?
My latest try is below, but that does not work:

   $desc = $xml->xpath('//image[name="'.$file.'"]/text');

Thanks!

1
Contributor
1
Reply
9
Views
1 Year
Discussion Span
Last Post by rouse
0

I found the answer with this bit of code:

$desc = $xml->xpath('image[name="' . $file . '"]');
                    $description = $desc[0]->text;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.