如何在php中访问xml文件的子元素,在这种情况下,有多个条目包含不同分辨率的URL

I have the following section of an xml file:

<ad:ad xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:resource="http://services.mobile.de/schema/resource" xmlns:ad="http://services.mobile.de/schema/ad" url="https://services.mobile.de/search-api/ad/266399529" xsi:schemaLocation="http://services.mobile.de/schema/ad http://services.mobile.de/schema/ad-1.0.xsd">
  <ad:images>
    <ad:image>
      <ad:representation size="S" url="$_18.JPG"/>
      <ad:representation size="XL" url="$_27.JPG"/>
      <ad:representation size="ICON" url="$_23.JPG"/>
      <ad:representation size="L" url="$_1.JPG"/>
      <ad:representation size="M" url="$_24.JPG"/>
    </ad:image>

I now want to access the representation element with the size "L" and read the URL there. But I just can't get access to these sub-elements.

This is what my code looks like so far

            $ad_ns = $ad_xml->children('http://services.mobile.de/schema/ad');
            foreach ( $ad_ns->images->image as $image )    {
              $image_attributes = $image->representation[0]->attributes();
              $image_url = (string) $image_attributes['gallery-url'];
              $image_url_big = str_replace("23.JPG", "27.JPG", $image_url);
              $image_url_small = str_replace("22.JPG", "1.JPG", $image_url);
            }

Can someone help me?