Search code examples
xpathsimplexml

xpath get node from inside value


Current xpath: Product/ProductMultimediaObject/MultimediaObject

Returns:

Array
(
    [0] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [ContentType] => application/pdf
                    [Date] => 2014-11-01 01:20:35
                    [Description] => Leaflet
                )

        )

)

But I'm currently just hoping that the found MultimediaObject is the correct one - which is not. I need to get the MultimediaObject where Description has a specific value.

What I've tried:

Product/ProductMultimediaObject/MultimediaObject[Description/text() = 'WhatIWant']
Product/ProductMultimediaObject/MultimediaObject/Description[text() = 'WhatIWant']

Solution

  • Your Desciption is an attribute. Try

    Product/ProductMultimediaObject/MultimediaObject[@Description = 'WhatIWant']
    

    or, for short,

    //MultimediaObject[@Description = 'WhatIWant']